Search in sources :

Example 1 with TermItem

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"));
    }
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) NotItem(com.yahoo.prelude.query.NotItem) Iterator(java.util.Iterator) Index(com.yahoo.prelude.Index) WordItem(com.yahoo.prelude.query.WordItem) TermItem(com.yahoo.prelude.query.TermItem)

Example 2 with TermItem

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;
}
Also used : DispatchForm(com.yahoo.search.query.textserialize.serializer.DispatchForm) TermItem(com.yahoo.prelude.query.TermItem)

Example 3 with TermItem

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;
            }
        }
    }
}
Also used : TermItem(com.yahoo.prelude.query.TermItem) CompositeItem(com.yahoo.prelude.query.CompositeItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Item(com.yahoo.prelude.query.Item) WordItem(com.yahoo.prelude.query.WordItem) TermItem(com.yahoo.prelude.query.TermItem)

Example 4 with TermItem

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);
}
Also used : TermItem(com.yahoo.prelude.query.TermItem) FlattenedItem(com.yahoo.prelude.semantics.engine.FlattenedItem)

Example 5 with TermItem

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;
}
Also used : TermItem(com.yahoo.prelude.query.TermItem)

Aggregations

TermItem (com.yahoo.prelude.query.TermItem)6 CompositeItem (com.yahoo.prelude.query.CompositeItem)3 WordItem (com.yahoo.prelude.query.WordItem)3 Item (com.yahoo.prelude.query.Item)2 PhraseItem (com.yahoo.prelude.query.PhraseItem)2 Index (com.yahoo.prelude.Index)1 NotItem (com.yahoo.prelude.query.NotItem)1 FlattenedItem (com.yahoo.prelude.semantics.engine.FlattenedItem)1 DispatchForm (com.yahoo.search.query.textserialize.serializer.DispatchForm)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1