コード例 #1
0
ファイル: Query.php プロジェクト: starsw001/solarium
 /**
  * Set the query string.
  *
  * This overwrites the current value
  *
  * @param string $query
  * @param array  $bind  Bind values for placeholders in the query string
  *
  * @return self Provides fluent interface
  */
 public function setQuery($query, $bind = null)
 {
     if (!is_null($bind)) {
         $helper = new Helper();
         $query = $helper->assemble($query, $bind);
     }
     return $this->setOption('query', $query);
 }
コード例 #2
0
ファイル: Parametrized.php プロジェクト: librette/solarium
 public function build()
 {
     if (!empty($this->parameters)) {
         $helper = new Helper();
         return $helper->assemble($this->query, $this->parameters);
     }
     return $this->query;
 }
コード例 #3
0
 public function testCacheControlWithoutCost()
 {
     $this->assertEquals('{!cache=true}', $this->helper->cacheControl(true));
 }
コード例 #4
0
ファイル: HelperTest.php プロジェクト: csemrm/solr-power
 public function testFilterControlCharacters()
 {
     $this->assertEquals('my string', $this->helper->filterControlCharacters("mystring"));
 }
コード例 #5
0
ファイル: FilterQuery.php プロジェクト: starsw001/solarium
 /**
  * Set the query string.
  *
  * This overwrites the current value
  *
  * @param string $query
  * @param array  $bind  Bind values for placeholders in the query string
  *
  * @return self Provides fluent interface
  */
 public function setQuery($query, $bind = null)
 {
     if (!is_null($bind)) {
         $helper = new Helper();
         $query = $helper->assemble($query, $bind);
     }
     $this->query = trim($query);
     return $this;
 }
コード例 #6
0
ファイル: SolrHelper.php プロジェクト: curveagency/intranet
 /**
  * Flatten a keys array into a single search string.
  *
  * @param array $keys
  *   The keys array to flatten, formatted as specified by
  *   \Drupal\search_api\Query\QueryInterface::getKeys().
  * @param bool $is_nested
  *   (optional) Whether the function is called for a nested condition.
  *   Defaults to FALSE.
  *
  * @return string
  *   A Solr query string representing the same keys.
  */
 public function flattenKeys(array $keys, $is_nested = FALSE)
 {
     $k = array();
     $or = $keys['#conjunction'] == 'OR';
     $neg = !empty($keys['#negation']);
     foreach ($keys as $key_nr => $key) {
         // We cannot use \Drupal\Core\Render\Element::children() anymore because
         // $keys is not a valid render array.
         if ($key_nr[0] === '#' || !$key) {
             continue;
         }
         if (is_array($key)) {
             $subkeys = $this->flattenKeys($key, TRUE);
             if ($subkeys) {
                 $nested_expressions = TRUE;
                 // If this is a negated OR expression, we can't just use nested keys
                 // as-is, but have to put them into parantheses.
                 if ($or && $neg) {
                     $subkeys = "({$subkeys})";
                 }
                 $k[] = $subkeys;
             }
         } else {
             $solariumHelper = new SolariumHelper();
             $key = $solariumHelper->escapePhrase(trim($key));
             $k[] = $key;
         }
     }
     if (!$k) {
         return '';
     }
     // Formatting the keys into a Solr query can be a bit complex. The following
     // code will produce filters that look like this:
     //
     // #conjunction | #negation | return value
     // ----------------------------------------------------------------
     // AND          | FALSE     | A B C
     // AND          | TRUE      | -(A AND B AND C)
     // OR           | FALSE     | ((A) OR (B) OR (C))
     // OR           | TRUE      | -A -B -C
     // If there was just a single, unnested key, we can ignore all this.
     if (count($k) == 1 && empty($nested_expressions)) {
         $k = reset($k);
         return $neg ? "*:* AND -{$k}" : $k;
     }
     if ($or) {
         if ($neg) {
             return '*:* AND -' . implode(' AND -', $k);
         }
         return '((' . implode(') OR (', $k) . '))';
     }
     $k = implode($neg || $is_nested ? ' AND ' : ' ', $k);
     return $neg ? "*:* AND -({$k})" : $k;
 }