Exact matches vs any word matches
-
wpsolrKeymaster1 year, 8 months ago #27876
Please replace your current WPSOLR version with this release: https://trello.com/c/qRvm86QT/177-add-exact-match-with-double-quoted-keywords-solr
The release includes the following fixes/improvements:
– Apply Solr exact search on double quoted keywords searchpgilpatParticipant1 year, 7 months ago #28002Greetings. We applied your release and it is providing strange results:
Enter keyword: love
love search
It returns 827 results, but if you click on the first link for 0:1.17, you get many results including love, levels, sovereignty, etc.
page results
The developer adjusted the tolerance. on .02, it won’t find fuzzy words, but on .03, it finds fuzzy words in addition to un-related words like levels.
Thanks again.wpsolrKeymaster1 year, 7 months ago #28010Data is processed with an analyser configured in the schema.xml provided by WPSOLR.
This analyser applies a series of filters (transformations) to your data and your queries.
“loving” and “love” have a common stem, hence both are retrieved with “love”.
You’ll find below the stemmer filter used with WPSOLR: “solr.PorterStemFilterFactory”You can edit the schema.xml and remove the stemmer eventually (reload the index, and reindex all your data).
< fieldType name="text" class="solr.TextField" positionIncrementGap="100">
< analyzer type="index">
< tokenizer class="solr.WhitespaceTokenizerFactory"/>
< filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="1"/>
< filter class="solr.LowerCaseFilterFactory"/>
< filter class="solr.EnglishPossessiveFilterFactory"/>
< filter class="solr.PorterStemFilterFactory"/>
< /analyzer>
< analyzer type="query">
< tokenizer class="solr.WhitespaceTokenizerFactory"/>
< filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="1"/>
< filter class="solr.LowerCaseFilterFactory"/>
< filter class="solr.EnglishPossessiveFilterFactory"/>
< /analyzer>
< /fieldType>- This reply was modified 1 year, 7 months ago by wpsolr.
pgilpatParticipant1 year, 7 months ago #28115Here is the response from devs:
Yes, We re-indexed the data after removing the stem filter. And got only exact match for both ( exact or anywords ) options. As of now, Dev removed the filter & re-indexed the data on https://tbwp.hostworks.com/. You can see that..
• Exact match is working as expected.
• Anywords match is also working as the same way as exact match ( due to the removal of stem filter )How can we implement both exact match & anywords match with WPSolr? We need to know what are the options they provided & where they are available in wp-admin?
The possible solution could be a series of processes..
• Add 2 field types & 2 new text fields with those 2 field types
• Field type one should use stem filter ( for anywords match ) & another shouldn’t use it ( for exact match )
• Populate same data in those 2 fields
• WPSolr should have an option to select which field to be searched ( in the admin UI ), If search is about to anywords match or exact match. But adding this option is not so easy. So we need to ask help from WPSolr team.wpsolrKeymaster1 year, 7 months ago #28126I understand you need to switch between 2 search field, one with analysers (the default “text”), one without analyser (let say “text_exact”).
You can define field “text_exact” and its custom analyser in Solr schema.xml, and even populate “text_exact” automatically with a
instruction (as already done for “text” field): <copyField source="title" dest="text_exact"/> <copyField source="tags" dest="text_exact"/> <copyField source="categories" dest="text_exact"/> <copyField source="content" dest="text_exact"/> <copyField source="permalink" dest="text_exact"/> <copyField source="comments" dest="text_exact"/>
After that, you need to switch the Solr’s query from “text:(truth)” to “text_exact:(truth)”, based on some url query parameter (you already have “exact_match”).
To do that, before the query is sent to Solr, you can catch the Solarium’s client object, and use its api to make the switch.An example in your custom class:
use Solarium\QueryType\Select\Query\Query; add_action( WPSOLR_Events::WPSOLR_ACTION_SOLARIUM_QUERY, [$this, 'wpsolr_action_query',], 10, 1 ); public function wpsolr_action_query( $parameters ) { if (...) { // url does not contains the parameter return; } /* This is the Solarium\QueryType\Select\Query\Query */ $solarium_query = $parameters[ WPSOLR_Events::WPSOLR_ACTION_SOLARIUM_QUERY__PARAM_SOLARIUM_QUERY ]; /* Retrieve the query like "text:(truth)" $query = solarium_query->getQuery(); /* Extract the default field (regexp, ...), and replace it with the exact field $query_exact = ... /* Save the query like "text_exact:(truth)" $query = solarium_query->setQuery(query_exact); }
pgilpatParticipant1 year, 7 months ago #28146We’ve updated the Solr schema.xml, added text_exact field and copyfield similar to text field type.
As wpsolr mentioned that need to update the Solr’s query based on url param before the query is sent to Solr.
I tried in enfold(truthbook-wp\wp-content\themes\enfold)
functions & functions-enfold.php its not working at all, Can you mention where we need to put these particular hooks?wpsolrKeymaster1 year, 7 months ago #28147in functions.php should be fine.
Here are more details: https://www.wpsolr.com/guide/actions-and-filters/
You must be logged in to reply to this topic.