Lucene – scoring direct hits
Check out the Similarity class in Lucene and call searcher.explain() on your document to find out the reason for the score. What you want to do is to boost a direct match.
Please read full article from Lucene – scoring direct hits
Check out the Similarity class in Lucene and call searcher.explain() on your document to find out the reason for the score. What you want to do is to boost a direct match.
//where fieldName is 'name' or 'description'
Query tmpQuery =
new
TermQuery(
new
Term(fieldName, searchString));
//boost the direct match
tmpQuery.setBoost(
2
.0f);
query.add(tmpQuery, BooleanClause.Occur.SHOULD);
//search for other occurences
tmpQuery =
new
WildcardQuery(
new
Term(fieldName,
"*"
+ searchString +
"*"
));
query.add(tmpQuery, BooleanClause.Occur.SHOULD);
Please read full article from Lucene – scoring direct hits
No comments:
Post a Comment