Changing the default operator from OR to AND in Solr (Magento Enterprise)

前端 未结 6 1327
一向
一向 2021-02-01 23:28

I\'m using Solr with Magento Enterprise. I\'m trying to change the default search operator from OR to AND to make searches more specific by default.

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-02 00:19

    My question is not so much about the syntax but where to configure this so it applies to all searches.
    

    To answer your question, I am quite sure that we need to specify the default operator for solrQueryParser in schema.xml and not in solrconfig.xml. As you mentioned, it is given as,

    < solrQueryParser defaultOperator="AND"/>
    

    The reason why you did not get expected results may be because of the following reason:

    If your search URL is something like,

    q=articles_summary:red+jacket
    

    Then what happens is, "red" is searched against field "articles_summary" but "jacket" is searched against your default search field (say "text") which if I am right will be a copy field containing copy of all searchable fields. Hence you will get a match for "red" in "articles_summary" and "jacket" in "text".

    To get what you expect, I suggest you use something like following URL after setting default operation to AND as you already did:

    q=articles_summary:red+articles_summary:jacket
    

    If you have multiple fields to search, you may have to do like this:

    q=articles_summary:red+articles_summary:jacket+articles_title:red+articles_title:jacket
    

提交回复
热议问题