use of com.yahoo.prelude.query.TermItem in project vespa by vespa-engine.
the class LiteralBoostSearcher method addLiterals.
private void addLiterals(RankItem rankTerms, Item item, IndexFacts.Session indexFacts) {
if (item == null)
return;
if (item instanceof NotItem) {
addLiterals(rankTerms, ((NotItem) item).getPositiveItem(), indexFacts);
} else if (item instanceof CompositeItem) {
for (Iterator<Item> i = ((CompositeItem) item).getItemIterator(); i.hasNext(); ) addLiterals(rankTerms, i.next(), indexFacts);
} else if (item instanceof TermItem) {
TermItem termItem = (TermItem) item;
Index index = indexFacts.getIndex(termItem.getIndexName());
if (index.getLiteralBoost())
rankTerms.addItem(new WordItem(toLowerCase(termItem.getRawWord()), index.getName() + "_literal"));
}
}
use of com.yahoo.prelude.query.TermItem in project vespa by vespa-engine.
the class TermConverter method itemToForm.
@Override
public DispatchForm itemToForm(Item item, ItemIdMapper itemIdMapper) {
TermItem termItem = (TermItem) item;
DispatchForm form = new DispatchForm(termItem.getItemType().name());
ItemInitializer.initializeForm(form, item, itemIdMapper);
form.addChild(getValue(termItem));
return form;
}
use of com.yahoo.prelude.query.TermItem in project vespa by vespa-engine.
the class InputCheckingSearcher method repeatedConsecutiveTermsInPhraseCheck.
private void repeatedConsecutiveTermsInPhraseCheck(PhraseItem phrase) {
if (phrase.getItemCount() > MAX_REPEATED_CONSECUTIVE_TERMS_IN_PHRASE) {
String prev = null;
int repeatedCount = 0;
for (int i = 0; i < phrase.getItemCount(); ++i) {
Item item = phrase.getItem(i);
if (item instanceof TermItem) {
TermItem term = (TermItem) item;
String current = term.getIndexedString();
if (prev != null) {
if (prev.equals(current)) {
repeatedCount++;
if (repeatedCount >= MAX_REPEATED_CONSECUTIVE_TERMS_IN_PHRASE) {
repeatedConsecutiveTermsInPhraseRejections.add();
throw new IllegalArgumentException("More than " + MAX_REPEATED_CONSECUTIVE_TERMS_IN_PHRASE + " ocurrences of term '" + current + "' in a row detected in phrase : " + phrase.toString());
}
} else {
repeatedCount = 0;
}
}
prev = current;
} else {
prev = null;
repeatedCount = 0;
}
}
}
}
use of com.yahoo.prelude.query.TermItem in project vespa by vespa-engine.
the class Condition method labelMatches.
/**
* Whether the label matches the current item, true if there is no current item
*/
protected boolean labelMatches(RuleEvaluation e) {
FlattenedItem flattenedItem = e.currentItem();
if (flattenedItem == null)
return true;
TermItem item = flattenedItem.getItem();
if (item == null)
return true;
return labelMatches(item, e);
}
use of com.yahoo.prelude.query.TermItem in project vespa by vespa-engine.
the class TermConverter method formToItem.
@Override
public Object formToItem(String name, ItemArguments arguments, ItemContext context) {
ensureOnlyOneChild(arguments);
String word = getWord(arguments);
TermItem item = newTermItem(word);
ItemInitializer.initialize(item, arguments, context);
return item;
}
Aggregations