Reputation: 61
If the query word is "ABCD", then after being tokenized it is "A" "BC" "D". I want to boost term "BC", so the query word is like this:
A BC^10 D" and phrase query "ABCD"
All query words users typing in will be processed like that automaticly so that important query terms will be boosted.
I guess I can custom a new Tokenizer to do it, but I don't know if it is feasible, or is there some other methods simpler.
Upvotes: 1
Views: 468
Reputation: 12538
You can do this using the QueryElevationComponent. If you put words like BC in your elevate.xml file, then those terms will be automatically boosted at query time. If you have added the componant to your request handler of course.
EDIT:
I think you meant boosting terms rather than documents for a term. I think in your case, it might work if you look for the specific term using regexes and whitelists and alter the string to include the boosts before you send to solr.
[Fact]
public void Boost()
{
var query = "ABCD";
var importantTerms = new List<string>{ "BC"};
importantTerms.ForEach(term => query = query.Replace(term, string.Format("+{0}^10+", term)));
Assert.Equal("A+BC^10+D", query);
}
Upvotes: 0