Search in sources :

Example 31 with PhraseItem

use of com.yahoo.prelude.query.PhraseItem in project vespa by vespa-engine.

the class ParseTestCase method testExplicitPhrase.

@Test
public void testExplicitPhrase() {
    Item root = tester.assertParsed("\"foo bar foobar\"", "\"foo bar foobar\"", Query.Type.ANY);
    assertTrue(root instanceof PhraseItem);
    assertTrue(((PhraseItem) root).isExplicit());
}
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) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Example 32 with PhraseItem

use of com.yahoo.prelude.query.PhraseItem in project vespa by vespa-engine.

the class InputCheckingSearcher method repeatedTermsInPhraseCheck.

private void repeatedTermsInPhraseCheck(PhraseItem phrase) {
    if (phrase.getItemCount() > MAX_REPEATED_TERMS_IN_PHRASE) {
        Map<String, Count> repeatedCount = new HashMap<>();
        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();
                Count count = repeatedCount.get(current);
                if (count != null) {
                    if (count.get() >= MAX_REPEATED_TERMS_IN_PHRASE) {
                        repeatedTermsInPhraseRejections.add();
                        throw new IllegalArgumentException("Phrase contains more than " + MAX_REPEATED_TERMS_IN_PHRASE + " occurrences of term '" + current + "' in phrase : " + phrase.toString());
                    }
                    count.inc();
                } else {
                    repeatedCount.put(current, new Count(1));
                }
            }
        }
    }
}
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) HashMap(java.util.HashMap) TermItem(com.yahoo.prelude.query.TermItem)

Example 33 with PhraseItem

use of com.yahoo.prelude.query.PhraseItem in project vespa by vespa-engine.

the class InputCheckingSearcher method checkPhrases.

private void checkPhrases(Item queryItem) {
    if (queryItem instanceof PhraseItem) {
        PhraseItem phrase = (PhraseItem) queryItem;
        repeatedConsecutiveTermsInPhraseCheck(phrase);
        repeatedTermsInPhraseCheck(phrase);
    } else if (queryItem instanceof CompositeItem) {
        CompositeItem asComposite = (CompositeItem) queryItem;
        for (ListIterator<Item> i = asComposite.getItemIterator(); i.hasNext(); ) {
            checkPhrases(i.next());
        }
    }
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) ListIterator(java.util.ListIterator) PhraseItem(com.yahoo.prelude.query.PhraseItem)

Aggregations

PhraseItem (com.yahoo.prelude.query.PhraseItem)33 WordItem (com.yahoo.prelude.query.WordItem)24 Test (org.junit.Test)23 CompositeItem (com.yahoo.prelude.query.CompositeItem)14 AndItem (com.yahoo.prelude.query.AndItem)13 Item (com.yahoo.prelude.query.Item)10 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)9 OrItem (com.yahoo.prelude.query.OrItem)5 PrefixItem (com.yahoo.prelude.query.PrefixItem)4 SubstringItem (com.yahoo.prelude.query.SubstringItem)4 SuffixItem (com.yahoo.prelude.query.SuffixItem)4 Query (com.yahoo.search.Query)4 IntItem (com.yahoo.prelude.query.IntItem)3 NotItem (com.yahoo.prelude.query.NotItem)3 RankItem (com.yahoo.prelude.query.RankItem)3 TermItem (com.yahoo.prelude.query.TermItem)2 PhrasingSearcher (com.yahoo.prelude.querytransform.PhrasingSearcher)2 Searcher (com.yahoo.search.Searcher)2 QueryTree (com.yahoo.search.query.QueryTree)2 Execution (com.yahoo.search.searchchain.Execution)2