diff options
author | Jon Bratseth <bratseth@gmail.com> | 2020-12-08 13:13:42 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2020-12-08 13:13:42 +0100 |
commit | 3c3a18816bea660ae19611e116c6b73793193ad4 (patch) | |
tree | 22ed0011ea61e5d7304b5394405c08057faa7f5d /container-search | |
parent | 2fe8b70c43865afd9c5c6970ecd53905e08c36b3 (diff) |
Provide access to the term to be replaced
Diffstat (limited to 'container-search')
-rw-r--r-- | container-search/src/main/java/com/yahoo/search/querytransform/NGramSearcher.java | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/querytransform/NGramSearcher.java b/container-search/src/main/java/com/yahoo/search/querytransform/NGramSearcher.java index 399ff6194c8..90bcebb53ad 100644 --- a/container-search/src/main/java/com/yahoo/search/querytransform/NGramSearcher.java +++ b/container-search/src/main/java/com/yahoo/search/querytransform/NGramSearcher.java @@ -107,7 +107,7 @@ public class NGramSearcher extends Searcher { */ protected Item splitToGrams(Item term, String text, int gramSize, Query query) { String index = ((HasIndexItem)term).getIndexName(); - CompositeItem gramsItem = createGramRoot(query); + CompositeItem gramsItem = createGramRoot((HasIndexItem)term, query); gramsItem.setIndexName(index); Substring origin = ((BlockItem)term).getOrigin(); for (Iterator<GramSplitter.Gram> i = getGramSplitter().split(text,gramSize); i.hasNext(); ) { @@ -130,12 +130,20 @@ public class NGramSearcher extends Searcher { * called by {@link #splitToGrams}. This hook is provided to make it easy to create a subclass which * matches grams using a different composite item, e.g an OrItem. * <p> - * This default implementation return new AndItem(); + * This default implementation returns createGramRoot(query). * + * @param term the term item this gram root is replacing in the query tree, + * typically used to access the index name of the term when that is required by the new gram root + * (such as in PhraseItem) * @param query the input query, to make it possible to return a different composite item type * depending on the query content * @return the composite item to add the gram items to in {@link #splitToGrams} */ + protected CompositeItem createGramRoot(HasIndexItem term, Query query) { + return createGramRoot(query); + } + + /** Creates the root of the query subtree without access to the term being replaced. */ protected CompositeItem createGramRoot(Query query) { return new AndItem(); } |