Search in sources :

Example 11 with PhraseItem

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

the class CollapsePhraseSearcherTestCase method testPositive2.

@Test
public void testPositive2() {
    AndItem root = new AndItem();
    root.addItem(new WordItem("a"));
    CompositeItem embedded = new AndItem();
    embedded.addItem(new WordItem("bcd"));
    CompositeItem phrase = new PhraseItem();
    phrase.addItem(new WordItem("def"));
    embedded.addItem(phrase);
    root.addItem(embedded);
    root.addItem(new WordItem("e"));
    assertEquals("AND a (AND bcd def) e", transformQuery(root));
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Example 12 with PhraseItem

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

the class CollapsePhraseSearcherTestCase method testNegative3.

@Test
public void testNegative3() {
    AndItem root = new AndItem();
    root.addItem(new WordItem("a"));
    CompositeItem embedded = new AndItem();
    embedded.addItem(new WordItem("bcd"));
    CompositeItem phrase = new PhraseItem();
    phrase.addItem(new WordItem("def"));
    phrase.addItem(new WordItem("ghi"));
    embedded.addItem(phrase);
    root.addItem(embedded);
    root.addItem(new WordItem("e"));
    assertEquals("AND a (AND bcd \"def ghi\") e", transformQuery(root));
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Example 13 with PhraseItem

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

the class CollapsePhraseSearcherTestCase method testPositive1.

@Test
public void testPositive1() {
    AndItem root = new AndItem();
    root.addItem(new WordItem("a"));
    PhraseItem embedded = new PhraseItem();
    embedded.addItem(new WordItem("bcd"));
    root.addItem(embedded);
    root.addItem(new WordItem("e"));
    assertEquals("AND a bcd e", transformQuery(root));
}
Also used : AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Example 14 with PhraseItem

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

the class CollapsePhraseSearcherTestCase method testSimplePositive.

@Test
public void testSimplePositive() {
    PhraseItem root = new PhraseItem();
    root.addItem(new WordItem("abc"));
    assertEquals("abc", transformQuery(root));
}
Also used : WordItem(com.yahoo.prelude.query.WordItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Example 15 with PhraseItem

use of com.yahoo.prelude.query.PhraseItem 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)

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