use of com.yahoo.prelude.query.SegmentItem in project vespa by vespa-engine.
the class CJKSearcher method transform.
private Item transform(Item root) {
if (root instanceof PhraseItem) {
PhraseItem asPhrase = (PhraseItem) root;
if (asPhrase.isExplicit() || hasOverlappingTokens(asPhrase))
return root;
AndItem replacement = new AndItem();
for (ListIterator<Item> i = ((CompositeItem) root).getItemIterator(); i.hasNext(); ) {
Item item = i.next();
if (item instanceof WordItem)
replacement.addItem(item);
else if (item instanceof PhraseSegmentItem) {
replacement.addItem(new AndSegmentItem((PhraseSegmentItem) item));
} else
// should never run, but hey... just convert and hope it's OK :)
replacement.addItem(item);
}
return replacement;
} else if (root instanceof PhraseSegmentItem) {
PhraseSegmentItem asSegment = (PhraseSegmentItem) root;
if (asSegment.isExplicit() || hasOverlappingTokens(asSegment))
return root;
else
return new AndSegmentItem(asSegment);
} else if (root instanceof SegmentItem) {
// avoid descending into AndSegmentItems and similar
return root;
} else if (root instanceof CompositeItem) {
for (ListIterator<Item> i = ((CompositeItem) root).getItemIterator(); i.hasNext(); ) {
Item item = i.next();
Item transformedItem = transform(item);
if (item != transformedItem) {
i.set(transformedItem);
}
}
return root;
}
return root;
}
use of com.yahoo.prelude.query.SegmentItem in project vespa by vespa-engine.
the class YqlParser method instantiatePhraseSegmentItem.
@NonNull
private Item instantiatePhraseSegmentItem(String field, OperatorNode<ExpressionOperator> ast, boolean forcePhrase) {
Substring origin = getOrigin(ast);
Boolean stem = getAnnotation(ast, STEM, Boolean.class, Boolean.TRUE, STEM_DESCRIPTION);
Boolean andSegmenting = getAnnotation(ast, AND_SEGMENTING, Boolean.class, Boolean.FALSE, "setting for whether to force using AND for segments on and off");
SegmentItem phrase;
List<String> words = null;
if (forcePhrase || !andSegmenting) {
phrase = new PhraseSegmentItem(origin.getValue(), origin.getValue(), true, !stem, origin);
} else {
phrase = new AndSegmentItem(origin.getValue(), true, !stem);
}
phrase.setIndexName(field);
if (resegment && getAnnotation(ast, IMPLICIT_TRANSFORMS, Boolean.class, Boolean.TRUE, IMPLICIT_TRANSFORMS_DESCRIPTION)) {
words = segmenter.segment(origin.getValue(), currentlyParsing.getLanguage());
}
if (words != null && words.size() > 0) {
for (String word : words) {
phrase.addItem(new WordItem(word, field, true));
}
} else {
for (OperatorNode<ExpressionOperator> word : ast.<List<OperatorNode<ExpressionOperator>>>getArgument(1)) {
phrase.addItem(instantiateWordItem(field, word, phrase.getClass(), SegmentWhen.NEVER));
}
}
if (phrase instanceof TaggableItem) {
leafStyleSettings(ast, (TaggableItem) phrase);
}
phrase.lock();
return phrase;
}
Aggregations