|
29 | 29 | import org.apache.lucene.queryparser.classic.ParseException; |
30 | 30 | import org.apache.lucene.search.BooleanClause; |
31 | 31 | import org.apache.lucene.search.BooleanQuery; |
| 32 | +import org.apache.lucene.search.BoostQuery; |
32 | 33 | import org.apache.lucene.search.FuzzyQuery; |
33 | 34 | import org.apache.lucene.search.MatchAllDocsQuery; |
34 | 35 | import org.apache.lucene.search.Query; |
|
52 | 53 | import java.util.logging.Logger; |
53 | 54 | import java.util.regex.Pattern; |
54 | 55 |
|
| 56 | +import static org.apache.lucene.search.BoostAttribute.DEFAULT_BOOST; |
| 57 | + |
55 | 58 | /** |
56 | 59 | * Used for parsing the text of a query for which suggestions should be retrieved. Decouples the query into 2 parts: |
57 | 60 | * {@link SuggesterQuery} for suggestions and ordinary {@link Query} which serves as a dependency of |
@@ -93,14 +96,17 @@ public String getQueryTextWithPlaceholder() { |
93 | 96 | } |
94 | 97 |
|
95 | 98 | @Override |
96 | | - protected Query newTermQuery(final Term term) { |
| 99 | + protected Query newTermQuery(final Term term, float boost) { |
97 | 100 | if (term.text().contains(identifier)) { |
98 | | - SuggesterPrefixQuery q = new SuggesterPrefixQuery(replaceIdentifier(term, identifier)); |
99 | | - this.suggesterQuery = q; |
| 101 | + Query q = new SuggesterPrefixQuery(replaceIdentifier(term, identifier)); |
| 102 | + this.suggesterQuery = (SuggesterPrefixQuery) q; |
| 103 | + if (boost != DEFAULT_BOOST) { |
| 104 | + q = new BoostQuery(q, boost); |
| 105 | + } |
100 | 106 | return q; |
101 | 107 | } |
102 | 108 |
|
103 | | - return super.newTermQuery(term); |
| 109 | + return super.newTermQuery(term, boost); |
104 | 110 | } |
105 | 111 |
|
106 | 112 | private Term replaceIdentifier(final Term term, final String identifier) { |
|
0 commit comments