diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-10-12 15:55:11 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-10-12 15:55:11 +0200 |
commit | 5e0502391c2ca7c4b0bfc9f4f652da2676f26314 (patch) | |
tree | 1fb5c7073f0af7b111d3290e4295a323d0d9ece2 /container-search | |
parent | 08f7a121fff008dd1307b106bd1b7d7a84433fe6 (diff) |
Add instance tags
Diffstat (limited to 'container-search')
4 files changed, 17 insertions, 15 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/handler/Json2SingleLevelMap.java b/container-search/src/main/java/com/yahoo/search/handler/Json2SingleLevelMap.java index bf0272f4f66..7dd1772a53e 100644 --- a/container-search/src/main/java/com/yahoo/search/handler/Json2SingleLevelMap.java +++ b/container-search/src/main/java/com/yahoo/search/handler/Json2SingleLevelMap.java @@ -22,9 +22,11 @@ import java.util.Map; * @author baldersheim */ class Json2SingleLevelMap { + private static final ObjectMapper jsonMapper = new ObjectMapper().configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); private final byte [] buf; private final JsonParser parser; + Json2SingleLevelMap(InputStream data) { try { buf = data.readAllBytes(); @@ -33,6 +35,7 @@ class Json2SingleLevelMap { throw new RuntimeException("Problem reading POSTed data", e); } } + Map<String, String> parse() { try { Map<String, String> map = new HashMap<>(); @@ -47,16 +50,17 @@ class Json2SingleLevelMap { throw new RuntimeException("Problem reading POSTed data", e); } } + void parse(Map<String, String> map, String parent) throws IOException { for (parser.nextToken(); parser.getCurrentToken() != JsonToken.END_OBJECT; parser.nextToken()) { String fieldName = parent + parser.getCurrentName(); JsonToken token = parser.nextToken(); if ((token == JsonToken.VALUE_STRING) || - (token == JsonToken.VALUE_NUMBER_FLOAT) || - (token == JsonToken.VALUE_NUMBER_INT) || - (token == JsonToken.VALUE_TRUE) || - (token == JsonToken.VALUE_FALSE) || - (token == JsonToken.VALUE_NULL)) { + (token == JsonToken.VALUE_NUMBER_FLOAT) || + (token == JsonToken.VALUE_NUMBER_INT) || + (token == JsonToken.VALUE_TRUE) || + (token == JsonToken.VALUE_FALSE) || + (token == JsonToken.VALUE_NULL)) { map.put(fieldName, parser.getText()); } else if (token == JsonToken.START_ARRAY) { map.put(fieldName, skipChildren(parser, buf)); @@ -71,6 +75,7 @@ class Json2SingleLevelMap { } } } + private String skipChildren(JsonParser parser, byte [] input) throws IOException { JsonLocation start = parser.getCurrentLocation(); parser.skipChildren(); @@ -78,4 +83,5 @@ class Json2SingleLevelMap { int offset = (int)start.getByteOffset() - 1; return new String(input, offset, (int)(end.getByteOffset() - offset), StandardCharsets.UTF_8); } + } 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 afd25132510..bcdc84c1808 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 @@ -69,8 +69,7 @@ public class NGramSearcher extends Searcher { private boolean rewriteToNGramMatching(Item item, int indexInParent, IndexFacts.Session indexFacts, Query query) { boolean rewritten = false; - if (item instanceof SegmentItem) { // handle CJK segmented terms which should be grams instead - SegmentItem segments = (SegmentItem)item; + if (item instanceof SegmentItem segments) { // handle CJK segmented terms which should be grams instead Index index = indexFacts.getIndex(segments.getIndexName()); if (index.isNGram()) { Item grams = splitToGrams(segments, toLowerCase(segments.getRawWord()), index.getGramSize(), query); @@ -78,13 +77,11 @@ public class NGramSearcher extends Searcher { rewritten = true; } } - else if (item instanceof CompositeItem) { - CompositeItem composite = (CompositeItem)item; + else if (item instanceof CompositeItem composite) { for (int i=0; i<composite.getItemCount(); i++) rewritten = rewriteToNGramMatching(composite.getItem(i), i, indexFacts, query) || rewritten; } - else if (item instanceof TermItem) { - TermItem term = (TermItem)item; + else if (item instanceof TermItem term) { Index index = indexFacts.getIndex(term.getIndexName()); if (index.isNGram()) { Item grams = splitToGrams(term,term.stringValue(), index.getGramSize(), query); @@ -149,11 +146,10 @@ public class NGramSearcher extends Searcher { } private void replaceItemByGrams(Item item, Item grams, int indexInParent) { - if (!(grams instanceof CompositeItem) || !(item.getParent() instanceof PhraseItem)) { // usually, simply replace + if (!(grams instanceof CompositeItem) || !(item.getParent() instanceof PhraseItem phraseParent)) { // usually, simply replace item.getParent().setItem(indexInParent, grams); } else { // but if the parent is a phrase, we cannot add the AND to it, so add each gram to the phrase - PhraseItem phraseParent = (PhraseItem)item.getParent(); phraseParent.removeItem(indexInParent); int addedTerms = 0; for (Iterator<Item> i = ((CompositeItem)grams).getItemIterator(); i.hasNext(); ) { diff --git a/container-search/src/main/java/com/yahoo/search/searchchain/AsyncExecution.java b/container-search/src/main/java/com/yahoo/search/searchchain/AsyncExecution.java index adab4d59ec0..205c65a6256 100644 --- a/container-search/src/main/java/com/yahoo/search/searchchain/AsyncExecution.java +++ b/container-search/src/main/java/com/yahoo/search/searchchain/AsyncExecution.java @@ -67,7 +67,7 @@ public class AsyncExecution { * Creates an async execution. * * @param chain the chain to execute - * @param context the the context of this + * @param context the context of this */ public AsyncExecution(Chain<? extends Searcher> chain, Execution.Context context) { this(context, chain); diff --git a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java index ae2a8800bbc..5b972e40774 100644 --- a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java @@ -65,7 +65,7 @@ import static org.junit.jupiter.api.Assertions.*; public class QueryTestCase { @Test - void testIt() throws Exception { + void testIt() { JSONObject newroot = new JSONObject("{\"key\": 3}"); var hit = new FastHit(); hit.setField("data", (JsonProducer) s -> s.append(newroot)); |