use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.
the class CJKSearcher method hasOverlappingTokens.
/*
* We have overlapping tokens (see
* com.yahoo.prelude.querytransform.test.CJKSearcherTestCase
* .testCjkQueryWithOverlappingTokens and ParseTestCase for an explanation)
* if the sum of length of tokens is greater than the lenght of the original
* word
*/
private boolean hasOverlappingTokens(PhraseSegmentItem segments) {
int segmentsLength = 0;
for (Iterator<Item> i = segments.getItemIterator(); i.hasNext(); ) {
WordItem segment = (WordItem) i.next();
segmentsLength += segment.getWord().length();
}
return segmentsLength > segments.getRawWord().length();
}
use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.
the class PhraseParser method forcedPhrase.
/**
* Ignores everything but words and numbers
*
* @return a phrase item if several words/numbers was found,
* a word item if only one was found
*/
private Item forcedPhrase() {
Item firstWord = null;
PhraseItem phrase = null;
while (tokens.hasNext()) {
Token token = tokens.next();
if (token.kind != Token.Kind.WORD && token.kind != Token.Kind.NUMBER) {
continue;
}
// Note, this depends on segment never creating AndItems when quoted
// (the second argument) is true.
Item newWord = segment(token);
if (firstWord == null) {
// First pass
firstWord = newWord;
} else if (phrase == null) {
// Second pass
phrase = new PhraseItem();
phrase.addItem(firstWord);
phrase.addItem(newWord);
} else {
// Following passes
phrase.addItem(newWord);
}
}
if (phrase != null) {
return phrase;
} else {
return firstWord;
}
}
use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.
the class ReferenceTermProduction method addMatches.
private void addMatches(RuleEvaluation e, ReferencedMatches referencedMatches) {
Item referencedItem = referencedMatches.toItem(getLabel());
if (referencedItem == null)
return;
e.addItem(referencedItem, getTermType());
}
use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.
the class ParseTestCase method testSubstringExtraSpace.
@Test
public void testSubstringExtraSpace() {
Item root = tester.assertParsed("*substring*", "* substring*", Query.Type.ANY);
assertTrue(root instanceof SubstringItem);
}
use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.
the class ParseTestCase method testIndexSuffixExtraSpace.
@Test
public void testIndexSuffixExtraSpace() {
Item root = tester.assertParsed("OR foo suffix", "foo:* suffix", Query.Type.ANY);
assertTrue(((OrItem) root).getItem(0) instanceof WordItem);
assertTrue(((OrItem) root).getItem(1) instanceof WordItem);
}
Aggregations