|
63 | 63 | import net.minidev.json.JSONValue;
|
64 | 64 | import net.minidev.json.parser.ParseException;
|
65 | 65 |
|
66 |
| -import static org.apache.lucene.server.handlers.RegisterFieldHandler.ANALYZER_TYPE; |
| 66 | +import static org.apache.lucene.server.handlers.RegisterFieldsHandler.ANALYZER_TYPE; |
67 | 67 |
|
68 | 68 | /** Handles {@code buildSuggest}. */
|
69 | 69 | public class BuildSuggestHandler extends Handler {
|
@@ -103,6 +103,7 @@ public class BuildSuggestHandler extends Handler {
|
103 | 103 | new Param("source", "Where to get suggestions from",
|
104 | 104 | new StructType(
|
105 | 105 | new Param("localFile", "Local file (to the server) to read suggestions + weights from; format is weight U+001F suggestion U+001F payload, one per line, with suggestion UTF-8 encoded. If this option is used then searcher, suggestField, weightField/Expression, payloadField should not be specified.", new StringType()),
|
| 106 | + new Param("hasContexts", "True if this file provides per-suggestion contexts.", new BooleanType(), true), |
106 | 107 | new Param("searcher", "Specific searcher version to use for pull suggestions to build. There are three different ways to specify a searcher version.",
|
107 | 108 | SearchHandler.SEARCHER_VERSION_TYPE),
|
108 | 109 | new Param("suggestField", "Field (from stored documents) containing the suggestion text", new StringType()),
|
@@ -142,6 +143,7 @@ public void load(IndexState indexState, JSONObject saveState) throws IOException
|
142 | 143 | Request source = r.getStruct("source");
|
143 | 144 | if (source.hasParam("localFile")) {
|
144 | 145 | source.getString("localFile");
|
| 146 | + source.getBoolean("hasContexts"); |
145 | 147 | } else {
|
146 | 148 | Request searcher = source.getStruct("searcher");
|
147 | 149 | if (searcher.hasParam("indexGen")) {
|
@@ -198,10 +200,10 @@ private Lookup getSuggester(IndexState indexState, String suggestName, Request r
|
198 | 200 | // nocommit allow passing a field name, and we use that
|
199 | 201 | // field name's analyzer?
|
200 | 202 | if (r.hasParam("analyzer")) {
|
201 |
| - indexAnalyzer = queryAnalyzer = RegisterFieldHandler.getAnalyzer(indexState, r, "analyzer"); |
| 203 | + indexAnalyzer = queryAnalyzer = RegisterFieldsHandler.getAnalyzer(indexState, r, "analyzer"); |
202 | 204 | } else {
|
203 |
| - indexAnalyzer = RegisterFieldHandler.getAnalyzer(indexState, r, "indexAnalyzer"); |
204 |
| - queryAnalyzer = RegisterFieldHandler.getAnalyzer(indexState, r, "queryAnalyzer"); |
| 205 | + indexAnalyzer = RegisterFieldsHandler.getAnalyzer(indexState, r, "indexAnalyzer"); |
| 206 | + queryAnalyzer = RegisterFieldsHandler.getAnalyzer(indexState, r, "queryAnalyzer"); |
205 | 207 | }
|
206 | 208 | if (indexAnalyzer == null) {
|
207 | 209 | r.fail("analyzer", "analyzer or indexAnalyzer must be specified");
|
@@ -420,10 +422,11 @@ public FinishRequest handle(final IndexState indexState, final Request r, Map<St
|
420 | 422 | if (!localFile.canRead()) {
|
421 | 423 | r.fail("localFile", "cannot read file");
|
422 | 424 | }
|
| 425 | + boolean hasContexts = source.getBoolean("hasContexts"); |
423 | 426 | searcher = null;
|
424 | 427 | // Pull suggestions from local file:
|
425 | 428 | try {
|
426 |
| - iterator = new FromFileTermFreqIterator(localFile); |
| 429 | + iterator = new FromFileTermFreqIterator(localFile, hasContexts); |
427 | 430 | } catch (IOException ioe) {
|
428 | 431 | r.fail("localFile", "cannot open file", ioe);
|
429 | 432 | }
|
|
0 commit comments