diff options
author | Jon Bratseth <bratseth@oath.com> | 2020-12-08 13:28:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-08 13:28:10 +0100 |
commit | 10464c859ccca2596e2b841612f8ea958330e4dc (patch) | |
tree | b3c19040582eb11bbae05d1c13410445ddf1d995 | |
parent | b7133833ca2ab63ebe388b65d645f463e228a461 (diff) | |
parent | 3c3a18816bea660ae19611e116c6b73793193ad4 (diff) |
Merge pull request #15736 from vespa-engine/bratseth/gram-term-access
Provide access to the term to be replaced
-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(); } |