diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-08-19 13:59:41 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-08-19 13:59:41 +0200 |
commit | f359fcf2bdbb50900b8be854eed38ae5fa12cf59 (patch) | |
tree | 32129089d1f679675038c8d02878c8c019443962 /container-search/src/main/java/com/yahoo | |
parent | cc96b081aa8ba8cd83f23042d58eb8e693b77b82 (diff) |
Apply defaultIndex to filters after parsing
Diffstat (limited to 'container-search/src/main/java/com/yahoo')
-rw-r--r-- | container-search/src/main/java/com/yahoo/prelude/query/parser/AbstractParser.java | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/query/parser/AbstractParser.java b/container-search/src/main/java/com/yahoo/prelude/query/parser/AbstractParser.java index f838e96c930..5da1f1a07be 100644 --- a/container-search/src/main/java/com/yahoo/prelude/query/parser/AbstractParser.java +++ b/container-search/src/main/java/com/yahoo/prelude/query/parser/AbstractParser.java @@ -7,6 +7,7 @@ import com.yahoo.prelude.Index; import com.yahoo.prelude.IndexFacts; import com.yahoo.prelude.query.AndSegmentItem; import com.yahoo.prelude.query.CompositeItem; +import com.yahoo.prelude.query.IndexedItem; import com.yahoo.prelude.query.Item; import com.yahoo.prelude.query.NullItem; import com.yahoo.prelude.query.PhraseItem; @@ -16,6 +17,7 @@ import com.yahoo.search.query.QueryTree; import com.yahoo.search.query.parser.Parsable; import com.yahoo.search.query.parser.ParserEnvironment; +import java.util.Iterator; import java.util.List; import java.util.ListIterator; @@ -166,6 +168,8 @@ public abstract class AbstractParser implements CustomParser { root = filterParser.applyFilter(root, filterToParse, parsingLanguage, indexFacts); } } + if (defaultIndex != null) + assignDefaultIndex(indexFacts.getCanonicName(defaultIndex), root); return simplifyPhrases(root); } @@ -228,6 +232,31 @@ public abstract class AbstractParser implements CustomParser { return detectionText.toString(); } + /** + * Assigns the default index to query terms having no default index. + * + * This will apply the default index to terms without it added through the filter parameter, + * where setting defaultIndex into state causes incorrect parsing. + * + * @param defaultIndex the default index to assign + * @param item the item to check + */ + private static void assignDefaultIndex(String defaultIndex, Item item) { + if (defaultIndex == null || item == null) return; + + if (item instanceof IndexedItem) { + IndexedItem indexName = (IndexedItem) item; + + if ("".equals(indexName.getIndexName())) + indexName.setIndexName(defaultIndex); + } + else if (item instanceof CompositeItem) { + Iterator<Item> items = ((CompositeItem)item).getItemIterator(); + while (items.hasNext()) + assignDefaultIndex(defaultIndex, items.next()); + } + } + private boolean is(Token.Kind kind, Token tokenOrNull) { if (tokenOrNull == null) return false; return kind.equals(tokenOrNull.kind); |