0

On a solr 4, I'm making a query for a word "black" and it returns me the results of the only product that have exact word - "black" in the name & desc. I'm searching only on the name and description.

However, there are many words that I want to include in search results.. like the result should include.. Jadeblack, Superblack, blackblue, nightblack and other words that have black in the string anytwhere and not just the word black.

However, such results are lesser relevant and should be ranked after results that have word "black".

Can you advise how should I change to get this kind of results.

Krunal
  • 2,967
  • 8
  • 45
  • 101

2 Answers2

2

Would suggest to use two fields. Copy Field the text_exact field to text_ngram field.

  1. text_exact - Exact match which will be boosted higher
  2. text_ngram - An ngram field which will help you to match partial matches with a boost lower than the exact match

You can configure the boost as text_exact^2 text_ngram^0.5

Jayendra
  • 52,349
  • 4
  • 80
  • 90
  • thank you for your answer. Would you suggest to do the wildcard search suggested by the Werzi2001 or search ngram as per your suggestion. I'm new to this and trying to understand which would be better. Thank you – Krunal May 23 '13 at 04:34
  • 1
    Wildcards are slower and an overhead for performance. Would suggest using ngrams as it is performed at index time so the searches would be much faster. – Jayendra May 23 '13 at 04:44
  • Thank you for your quick answer. I would like to try with this. +1 – Krunal May 23 '13 at 04:51
  • Sorry for delayed updated. This worked perfectly. Thanks Jayendra! – Krunal Jun 07 '13 at 10:53
0

You can use wildcards in your search term on a string type field. For example:

name:*black* OR description:*black*

With this search you get any results that have "black" in "name" or "description" and it doesn't have to be an exact match. In order to sort according to the quality of the match i think you would have to define a boost for the exact match and sort by the score. But this i have not done yet.

Just in case you didn't know yet. Searches on the type string are case sensitive by default. So you would not find matches for "Black" (except you really have a document where it is written in capital case). To change this behaviour you must define your own case insensitive string type:

<fieldType name="string_ci" class="solr.TextField" sortMissingLast="true" omitNorms="true">
    <analyzer type="query">
        <tokenizer class="solr.KeywordTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
</fieldType>

But this doesn't work for wild card search (as for "black"). In that case you would have to transform every search term that should include wildcards to lower case before sending to solr.

A different solution would be to use a different type (for example "text") instead of "string".

Werzi2001
  • 2,035
  • 1
  • 18
  • 41