Exact matches vs any word matches

Tagged:
  • wpsolr
    Keymaster
    1 year, 4 months ago #27874

    We are Paris time (CET).
    The only other option would be a custom development for your needs.

    pgilpat
    Participant
    1 year, 4 months ago #27875

    Can you please update WPSolr to accept the double quotes? I’ve spoken with out developers and that will work, thank you! How soon can that be done? I’m sorry to push, but we are on a tight deadline.

    wpsolr
    Keymaster
    1 year, 4 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 search

    pgilpat
    Participant
    1 year, 3 months ago #28002

    Greetings. 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.

    wpsolr
    Keymaster
    1 year, 3 months ago #28003

    WPSOLR marks search results with highlighting, not page details. What you see on link for 0:1.17 is not from WPSOLR (level, …).

    pgilpat
    Participant
    1 year, 3 months ago #28009

    Ok, but why are you returning results like loving when this is an exact match search?

    wpsolr
    Keymaster
    1 year, 3 months ago #28010

    Data 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, 3 months ago by wpsolr.
    pgilpat
    Participant
    1 year, 3 months ago #28057

    Thank you. We’ll try to implement.

    pgilpat
    Participant
    1 year, 3 months ago #28115

    Here 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.

    pgilpat
    Participant
    1 year, 3 months ago #28125

    Greetings,
    Sorry to push, but we are on deadline for going live on the 1st of November, do you have a response please?

    wpsolr
    Keymaster
    1 year, 3 months ago #28126

    I 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);
    }

    pgilpat
    Participant
    1 year, 3 months ago #28146

    We’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?

    wpsolr
    Keymaster
    1 year, 3 months ago #28147

    in functions.php should be fine.

    Here are more details: https://www.wpsolr.com/guide/actions-and-filters/

    pgilpat
    Participant
    1 year, 3 months ago #28148

    in the main theme directory? he tried in the child theme functions.php and it did not work.

    wpsolr
    Keymaster
    1 year, 3 months ago #28149

    Child theme functions.php is preferred indeed.

Viewing 15 posts - 16 through 30 (of 43 total)

You must be logged in to reply to this topic.