Solr search response Order : token position based

70 views Asked by At

I want search results document in sorted order of matched token position

example: I have following docs:

     1. indian institute of technology
     2. cultural arts institute
     3. institute of Management
     4. institute of Arts


search query : ins*
localhost:6983/solr/ts/select?fl=name&indent=true&q.op=OR&q=name%3Ains*

Expected response : 

     3. institute of Management  ----> (institute position ->1)
     4. institute of Arts        -----> (institute position ->1)
     1. indian institute of technology --> (institute position ->2)
     2. cultural arts institute   ------> (institute position ->3)

file : managed-schema


  <fieldType name="single_keyword" class="solr.TextField" positionIncrementGap="100">
    <analyzer type="index">
    <tokenizer class="solr.ClassicTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
    <analyzer type="query">
    <tokenizer class="solr.ClassicTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
  </fieldType>



Debug reference : 
http://localhost:6983/solr/ts/select?fl=name&indent=true&q.op=OR&q=name%3Ains*&debug=true

"debug": {
"rawquerystring": "name:ins*",
"querystring": "name:ins*",
"parsedquery": "name:ins*",
"parsedquery_toString": "name:ins*",
"explain": {
"institute_187": "\n1.0 = name:ins*\n",
"institute_188": "\n1.0 = name:ins*\n",
"institute_189": "\n1.0 = name:ins*\n",
"institute_1036": "\n1.0 = name:ins*\n",
"institute_1037": "\n1.0 = name:ins*\n",
"institute_2027": "\n1.0 = name:ins*\n",
"institute_2028": "\n1.0 = name:ins*\n",
"institute_2029": "\n1.0 = name:ins*\n"
},
"QParser": "LuceneQParser",
"timing": {......}}}

I Have tried this with autoSugest but it doesn't serve my use case, drawback of using autosuggest: unable to run filter on multiple value and field, unable to return multiple fields in response

1

There are 1 answers

0
Ben Borchard On

There may be an easier way to accomplish what you want, but this could definitely be handled using a a custom scorer. This blog explains the process of creating a custom scorer and outlines other angles through which you may be able to tackle this issue