Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lucene: how to boost some specific field

In my case, documents have two fields, for example, "title" and "views". "views" is represented the num of times that people have visited this document. like: "title":"iphone", "views":"10". I have to develop a strategy that will assign some weights to views, such as the relevance score is calculated by score(title)*0.8+score(views)*0.2. Does lucene can do this? And I want to know whether there are some algorithms related to this question.

like image 737
remy Avatar asked Mar 22 '12 19:03

remy


People also ask

What is Lucene boost?

Score Boosting Lucene allows influencing search results by "boosting" in more than one level: Document level boosting - while indexing - by calling document. setBoost() before a document is added to the index. Document's Field level boosting - while indexing - by calling field.

How do you use the wildcard in Lucene?

Lucene supports single and multiple character wildcard searches within single terms (not within phrase queries). To perform a single character wildcard search use the "?" symbol. To perform a multiple character wildcard search use the "*" symbol. You can also use the wildcard searches in the middle of a term.

How do you find special characters in Lucene?

You can't search for special characters in Lucene Search. These are + - = && || > < ! ( ) { } [ ] ^ " ~ * ? : \ / @. You can search for special characters, with the exception of the @ character, in a field-level search as long as you escape them using \ before the special character.


1 Answers

If you get here after 2020, in Lucene 8.5.2.

  1. Document.setBoost() doesn't exist anymore.
  2. Field.setBoost() doesn't exist anymore.
  3. Query.setBoost() doesn't exist anymore.

The ways to go:

  1. Wrap your Query (any Query but probably TermQuery in this case) in à BoostQuery

    Query boosted = new BoostQuery(query, 2f);
    
  2. Use the caret ^ symbol in your query parser syntax.

  3. Specify boosts in MultiFiledQueryParser.
  4. Use PerFieldSimilarityWrapper and adjust score per field.
like image 63
cquezel Avatar answered Oct 03 '22 18:10

cquezel