: > 1 bomb blast in kabul : > : > 2 kabul bomb blast : > : > 3 3 people killed in serial bomb blast in kabul ... : > I want 2nd result should come first while user search by "kabul". : > : > Because kabul is on 1st postion in that sentance. Similarly 1st result : > should come on 2nd and 3rd should come last.
One way to implement this would be with a "SpanFirstQuery" but I don't beleive there are any QParsers in Solr (out of hte box) that produce SpanFirstQueries, so you'd have to customize. An alternative appraoch that people have been doing since long before Span Queries have existed, is to index a special marker token (that won't ever appera in your text) at the begining of your field values, and then search for a slopy phrase containing your marker token and the word your user is looking for -- because sloppy phrase queries inherently score documents higher the closer the terms are to eachother So if you choose $^$^$ as your marker token, your three sentences would become... 1: $^$^$ bomb blast in kabul 2: $^$^$ kabul bomb blast 3: $^$^$ 3 people killed in serial bomb blast in kabul And your query would be something like "$^$^$ kabul"~1000 -Hoss