protected function addEDisMax() { $edismax = $this->query->getEDisMax(); if ($this->settings['features']['eDisMax']['queryFields']) { $edismax->setQueryFields($this->settings['features']['eDisMax']['queryFields']); } if ($this->settings['features']['eDisMax']['minimumMatch']) { $edismax->setMinimumMatch($this->settings['features']['eDisMax']['minimumMatch']); } if ($this->settings['features']['eDisMax']['phraseFields']) { $edismax->setPhraseFields($this->settings['features']['eDisMax']['phraseFields']); } if ($this->settings['features']['eDisMax']['phraseSlop']) { $edismax->setPhraseSlop($this->settings['features']['eDisMax']['phraseSlop']); } if ($this->settings['features']['eDisMax']['queryPhraseSlop']) { $edismax->setQueryPhraseSlop($this->settings['features']['eDisMax']['queryPhraseSlop']); } if ($this->settings['features']['eDisMax']['tie']) { $edismax->setTie($this->settings['features']['eDisMax']['tie']); } if ($this->settings['features']['eDisMax']['boostQuery']) { $edismax->setBoostQuery($this->settings['features']['eDisMax']['boostQuery']); } if ($this->settings['features']['eDisMax']['boostFunctions']) { $edismax->setBoostFunctions($this->settings['features']['eDisMax']['boostFunctions']); } if ($this->settings['features']['eDisMax']['boostFunctionsMult']) { $edismax->setBoostFunctionsMult($this->settings['features']['eDisMax']['boostFunctions']); } if ($this->settings['features']['eDisMax']['phraseBigramFields']) { $edismax->setPhraseBigramFields($this->settings['features']['eDisMax']['phraseBigramFields']); } if ($this->settings['features']['eDisMax']['phraseBigramSlop']) { $edismax->setPhraseBigramSlop($this->settings['features']['eDisMax']['phraseBigramSlop']); } if ($this->settings['features']['eDisMax']['phraseTrigramFields']) { $edismax->setPhraseTrigramFields($this->settings['features']['eDisMax']['phraseTrigramFields']); } if ($this->settings['features']['eDisMax']['phraseTrigramSlop']) { $edismax->setPhraseTrigramSlop($this->settings['features']['eDisMax']['phraseTrigramSlop']); } }
/** * Set the query keywords. * * @param Query $solarium_query * @param string $keywords */ private function set_keywords(Query $solarium_query, $keywords) { $query_field_name = ''; $keywords = trim($keywords); if (!WPSOLR_Global::getOption()->get_search_fields_is_active()) { // No search fields selected, use the default search field $query_field_name = WpSolrSchema::_FIELD_NAME_DEFAULT_QUERY . ':'; } else { /// Use search fields with their boost defined in qf instead of default field 'text' $query_fields_str = $this->get_query_fields(); if (!empty($query_fields_str)) { $solarium_query->getEDisMax()->setQueryFields($query_fields_str); } /// Add boosts on field values $query_boosts_fields_str = $this->get_query_boosts_fields(); if (!empty($query_boosts_fields_str)) { $solarium_query->getEDisMax()->setBoostQuery($query_boosts_fields_str); } } if (WPSOLR_Global::getOption()->get_search_is_partial_matches()) { // Add '*' to each world of the query string. // 'word1 word2 ' => 'word1* word2* ' $keywords1 = preg_replace('/(\\S+)/i', '$1*', $keywords); if ($keywords1 === $keywords . '*') { // then use 'OR' to ensure results include the exact keywords also (not only beginning with keywords) if there is one word only $keywords = $keywords . ' OR ' . $keywords1; } else { $keywords = $keywords1; } $solarium_query->setQuery($query_field_name . !empty($keywords) ? $keywords : '*'); } elseif (WPSOLR_Global::getOption()->get_search_is_fuzzy_matches()) { $keywords = preg_replace('/(\\S+)/i', '$1~', $keywords); } $this->is_query_wildcard = empty($keywords) || '*' === $keywords; // Escape Solr special caracters $keywords = $this->escape_solr_special_catacters($keywords); $solarium_query->setQuery($query_field_name . (!$this->is_query_wildcard ? $keywords : '*')); }