What’s New in Apache Lucene 2.9

Page 17

Although constant-scoring is now the default behavior, the older scoring mode is still available for multiterm queries in 2.9. Beyond that, you can choose one of the following scoring modes:

Filtered constant score: rewrites the multiterm query into a ConstantScoreQuery in combination with a filter to match all relevant documents.

BooleanQuery constant score: rewrites the multiterm query into a ConstantScoreQuery based on a BooleanQuery by translating each term into an optional Boolean clause. This mode still has a limitation of maxClauseCount and might raise an exception if the query has too many Boolean clauses.

Conventional scoring (not recommended): rewrites the multiterm query into an ordinary BooleanQuery.

Automatic constant score (default): tries to choose the best constant score mode (Filter or BooleanQuery) based on term and document counts from the query. If the number of terms and documents is small enough, BooleanQuery is chosen, otherwise the query rewrites to a filter-backed ConstantScoreQuery.

You can change the scoring mode by passing an implementation of RewriteMethod to MultiTermQuery.setRewriteMethod() as shown in the code example below. PrefixQuery prefixQuery = new PrefixQuery(new Term("aField", "luc")); prefixQuery.setRewriteMethod( MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE); Explicitly setting a filtered constant-score RewriteMethod on a PrefixQuery

Payloads The Payloads feature, though originally added in a previous version of Lucene, remains pretty new to most programmers. A payload is essentially a byte array that is associated with a particular term in the index. Payloads can be associated with a single term during text analysis and subsequently committed directly to the index. On the search side, these byte arrays are accessible to influence the scoring for a particular term, or even to filter entire documents.

What’s New in Lucene 2.9 A Lucid Imagination Technical White Paper • October 2009

Page 14


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.