Search in sources :

Example 6 with Item

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

Example 7 with Item

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

Example 8 with Item

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

Example 9 with Item

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);
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) IntItem(com.yahoo.prelude.query.IntItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) WordItem(com.yahoo.prelude.query.WordItem) NotItem(com.yahoo.prelude.query.NotItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) Test(org.junit.Test)

Example 10 with Item

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);
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) IntItem(com.yahoo.prelude.query.IntItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) WordItem(com.yahoo.prelude.query.WordItem) NotItem(com.yahoo.prelude.query.NotItem) WordItem(com.yahoo.prelude.query.WordItem) OrItem(com.yahoo.prelude.query.OrItem) Test(org.junit.Test)

Aggregations

Item (com.yahoo.prelude.query.Item)116 AndItem (com.yahoo.prelude.query.AndItem)85 CompositeItem (com.yahoo.prelude.query.CompositeItem)82 WordItem (com.yahoo.prelude.query.WordItem)73 PhraseItem (com.yahoo.prelude.query.PhraseItem)66 NotItem (com.yahoo.prelude.query.NotItem)62 RankItem (com.yahoo.prelude.query.RankItem)60 SubstringItem (com.yahoo.prelude.query.SubstringItem)60 Test (org.junit.Test)58 OrItem (com.yahoo.prelude.query.OrItem)57 PrefixItem (com.yahoo.prelude.query.PrefixItem)53 SuffixItem (com.yahoo.prelude.query.SuffixItem)53 IntItem (com.yahoo.prelude.query.IntItem)52 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)51 NullItem (com.yahoo.prelude.query.NullItem)24 Query (com.yahoo.search.Query)22 EquivItem (com.yahoo.prelude.query.EquivItem)14 NearItem (com.yahoo.prelude.query.NearItem)14 ExactStringItem (com.yahoo.prelude.query.ExactStringItem)12 IndexedItem (com.yahoo.prelude.query.IndexedItem)12