Exact Match Setup
To set a field(s) for exact matching, add another field in the Schema.xml and copy the content into it using copyField
<field name="title" type="text" indexed="true" stored="true" /> <field name="titleExact" type="textExact" indexed="true" stored="true" /> <copyField source="title" dest="titleExact"/> |
You would notice that the data type for titleExact is set to "textExact" (defined below), although similar exact match effect can be achieved by setting the datatype to "string" but with adding our own datatype we can further fine tune by adding appropriate tokenizer and filters.
<fieldType name="textExact" class="solr.TextField" positionIncrementGap="100" > <analyzer type="index"> <tokenizer class="solr.WhitespaceTokenizerFactory"/> <filter class="solr.LimitTokenCountFilterFactory" maxTokenCount="20"/> <filter class="solr.LowerCaseFilterFactory"/> </analyzer> <analyzer type="query"> <tokenizer class="solr.WhitespaceTokenizerFactory"/> <filter class="solr.LimitTokenCountFilterFactory" maxTokenCount="20"/> <filter class="solr.LowerCaseFilterFactory"/> </analyzer> |
Here I have used WhiteSpaceTokenizer without stopwords or stemming filters. I am using LimitTokenCounterFilter to limit the number of tokens and LowerCaseFilter to make the matching case-insensitive. We can further fine tune the textExact dataType to make the exact match a bit more lenient or strict per our use case.
Putting it All Together
Now to boost the exact match field and phrase matching, in the SolrConfig.xml -
<str name="qf">title titleExact^10</str> <str name="pf">title^10 titleExact^100</str> |
Now for both query and phrase matching we are boosting the exact matching field "titleExact" match higher than the non-exact matching field "title", also the same fields are boosted higher for phrase search (pf) compare to query or keyword search (qf). This would be a simple and first step to improving relevancy.
Why thank you sir.
ReplyDeleteHello,
ReplyDeleteThanks for this nice article,
I am trying to apply to this to my project. I have in schema.xml:
in solrconfig.xml:
explicit
json
true
text
How will I extend solrconfig to include title_exact?
Thanks
@Service Broker, Based on how you are importing data, using the DataImportHandler or the curl based imports, you can apply exact matching on the fields you are already importing. In my example above, I am importing the field title and I have extended the field in my Schema.xml by copying the content from the same field into another field "title_exact" and applying fieldType to it.
ReplyDeleteHope this helps.
Thank you! It saved my day :)
ReplyDeletehelpful post. saved my day
ReplyDeleteThanks,
does the last part, with the added lines for solrconfig.xml need to go inside one of the handlers that's already defined in solrconfig.xml?
ReplyDeleteYes, "pf" and "qf" is defined within your SearchHandler.
DeleteYour blog has given me that thing which I never expect to get from all over the websites. Nice post guys!
ReplyDeleteThank you, happy to help
DeleteIndeed an informative post. Thanks for sharing.
ReplyDeleteCompany registration in UAE
Hello, I Like your blog, I wanted to leave a little comment to support you and wish you a good continuation. Wish you best of luck for all your best efforts. Rak free zone
ReplyDeleteI wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post. palm hills alexandria
ReplyDeleteThanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. https://thegameroof.com/where-can-you-get-cheap-boost-in-wow-shadowlands
ReplyDeleteelo boost league I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much.
ReplyDeleteCool and that i have a neat provide: Whole House Renovation Cost old house renovation ideas
ReplyDeleteHow to set up a company in Dubai involves several key steps: selecting the right business structure, obtaining a business license, and registering with the relevant authorities. For a smooth process, consult experts like Corp Line, who can guide you through the complexities of company formation and ensure compliance with local regulations.
ReplyDeleteMeydan Freezone Company Set Up provides excellent benefits for entrepreneurs, including 100% ownership and tax exemptions. Establishing your business here involves selecting the right license and submitting required documents. Corp Line offers expert guidance throughout the process, ensuring a seamless setup and compliance with all regulations in Meydan Freezone.
ReplyDeleteCompany Formation Dubai involves choosing the right business structure, registering with the Department of Economic Development, and obtaining the necessary licenses. This process can be complex, but with the right guidance, it becomes manageable. Corp Line offers expert assistance to streamline your company formation journey and ensure compliance with local regulations.
ReplyDelete