use of com.yahoo.prelude.query.ExactStringItem in project vespa by vespa-engine.
the class YqlParser method instantiateWordItem.
@NonNull
private Item instantiateWordItem(String field, String rawWord, OperatorNode<ExpressionOperator> ast, Class<?> parent, SegmentWhen segmentPolicy, boolean exactMatch, Language language) {
String wordData = rawWord;
if (getAnnotation(ast, NFKC, Boolean.class, Boolean.FALSE, "setting for whether to NFKC normalize input data")) {
// NOTE: If this is set to FALSE (default), we will still NFKC normalize text data
// during tokenization/segmentation, as that is always turned on also on the indexing side.
wordData = normalizer.normalize(wordData);
}
boolean fromQuery = getAnnotation(ast, IMPLICIT_TRANSFORMS, Boolean.class, Boolean.TRUE, IMPLICIT_TRANSFORMS_DESCRIPTION);
boolean prefixMatch = getAnnotation(ast, PREFIX, Boolean.class, Boolean.FALSE, "setting for whether to use prefix match of input data");
boolean suffixMatch = getAnnotation(ast, SUFFIX, Boolean.class, Boolean.FALSE, "setting for whether to use suffix match of input data");
boolean substrMatch = getAnnotation(ast, SUBSTRING, Boolean.class, Boolean.FALSE, "setting for whether to use substring match of input data");
Preconditions.checkArgument((prefixMatch ? 1 : 0) + (substrMatch ? 1 : 0) + (suffixMatch ? 1 : 0) < 2, "Only one of prefix, substring and suffix can be set.");
@NonNull final TaggableItem wordItem;
if (exactMatch) {
wordItem = new ExactStringItem(wordData, fromQuery);
} else if (prefixMatch) {
wordItem = new PrefixItem(wordData, fromQuery);
} else if (suffixMatch) {
wordItem = new SuffixItem(wordData, fromQuery);
} else if (substrMatch) {
wordItem = new SubstringItem(wordData, fromQuery);
} else {
switch(segmentPolicy) {
case NEVER:
wordItem = new WordItem(wordData, fromQuery);
break;
case POSSIBLY:
if (shouldResegmentWord(field, fromQuery)) {
wordItem = resegment(field, ast, wordData, fromQuery, parent, language);
} else {
wordItem = new WordItem(wordData, fromQuery);
}
break;
case ALWAYS:
wordItem = resegment(field, ast, wordData, fromQuery, parent, language);
break;
default:
throw new IllegalArgumentException("Unexpected segmenting rule: " + segmentPolicy);
}
}
if (wordItem instanceof WordItem) {
prepareWord(field, ast, fromQuery, (WordItem) wordItem);
}
if (// mark the language used, unless it's the default
language != Language.ENGLISH)
((Item) wordItem).setLanguage(language);
return (Item) leafStyleSettings(ast, wordItem);
}
use of com.yahoo.prelude.query.ExactStringItem in project vespa by vespa-engine.
the class YqlParserTestCase method testRaw.
@Test
public void testRaw() {
Item root = parse("select foo from bar where baz contains (\"yoni jo dima\");").getRoot();
assertTrue(root instanceof WordItem);
assertFalse(root instanceof ExactStringItem);
assertEquals("yoni jo dima", ((WordItem) root).getWord());
root = parse("select foo from bar where baz contains ([{\"grammar\":\"raw\"}]\"yoni jo dima\");").getRoot();
assertTrue(root instanceof WordItem);
assertFalse(root instanceof ExactStringItem);
assertEquals("yoni jo dima", ((WordItem) root).getWord());
root = parse("select foo from bar where userInput(\"yoni jo dima\");").getRoot();
assertTrue(root instanceof AndItem);
AndItem andItem = (AndItem) root;
assertEquals(3, andItem.getItemCount());
root = parse("select foo from bar where [{\"grammar\":\"raw\"}]userInput(\"yoni jo dima\");").getRoot();
assertTrue(root instanceof WordItem);
assertTrue(root instanceof ExactStringItem);
assertEquals("yoni jo dima", ((WordItem) root).getWord());
}
Aggregations