Solr search from beginning of string

341 views Asked by At

I need to boost results which are found from beginning of string. For Example i have to countries: Egypt and Seychelles.

User types "e" in a text field and solr response will be:

  • Seychelles
  • Egypt

But as you can see "Egypt" starts with "e". And i need this result to be boosted up:

  • Egypt
  • Seychelles

Any other results should be scored as usual. Is there any kind of special tokenizers/serializers? Or may be special characters in SolrQuery syntax?

UPD:

Part of my schema.xml which describes text field type:

<fieldType name="text" class="solr.TextField" omitNorms="false">
  <analyzer type="index">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StandardFilterFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.NGramFilterFactory" minGramSize="1" maxGramSize="20" side="front" />
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StandardFilterFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>
1

There are 1 answers

0
nick.skriabin On BEST ANSWER

Problem solved by using EdgeNGramFilterFactory instead of NGramFilterFactory:

<fieldType name="text_start_end" class="solr.TextField" omitNorms="false">
  <analyzer>
    <tokenizer class="solr.ClassicTokenizerFactory"/>
    <filter class="solr.PositionFilterFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="20" side="front" />
  </analyzer>
</fieldType>