Search in sources :

Example 86 with WordItem

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

the class PhrasingSearcherTestCase method testMultiplePhrases.

@Test
public void testMultiplePhrases() {
    Searcher searcher = new PhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa");
    Query query = new Query();
    AndItem andItem = new AndItem();
    andItem.addItem(new WordItem("tudor", "someindex"));
    andItem.addItem(new WordItem("tudor", "someindex"));
    andItem.addItem(new WordItem("vidor", "someindex"));
    andItem.addItem(new WordItem("vidor", "someindex"));
    OrItem orItem = new OrItem();
    andItem.addItem(orItem);
    orItem.addItem(new WordItem("tudor"));
    AndItem andItem2 = new AndItem();
    andItem2.addItem(new WordItem("this", "anotherindex"));
    andItem2.addItem(new WordItem("is", "anotherindex"));
    andItem2.addItem(new WordItem("a", "anotherindex"));
    andItem2.addItem(new WordItem("test", "anotherindex"));
    andItem2.addItem(new WordItem("tudor", "anotherindex"));
    andItem2.addItem(new WordItem("vidor", "anotherindex"));
    orItem.addItem(andItem2);
    orItem.addItem(new WordItem("vidor"));
    query.getModel().getQueryTree().setRoot(andItem);
    new Execution(searcher, Execution.Context.createContextStub()).search(query);
    assertEquals("AND someindex:tudor someindex:\"tudor vidor\" someindex:vidor (OR tudor (AND anotherindex:\"this is a test\" anotherindex:\"tudor vidor\") vidor)", query.getModel().getQueryTree().getRoot().toString());
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) Searcher(com.yahoo.search.Searcher) PhrasingSearcher(com.yahoo.prelude.querytransform.PhrasingSearcher) WordItem(com.yahoo.prelude.query.WordItem) PhrasingSearcher(com.yahoo.prelude.querytransform.PhrasingSearcher) OrItem(com.yahoo.prelude.query.OrItem) Test(org.junit.Test)

Example 87 with WordItem

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

the class ItemEncodingTestCase method testWandItemEncoding.

@Test
public void testWandItemEncoding() {
    WordItem a = new WordItem("a");
    WordItem b = new WordItem("b");
    WeakAndItem wand = new WeakAndItem();
    wand.addItem(a);
    wand.addItem(b);
    ByteBuffer buffer = ByteBuffer.allocate(128);
    int count = wand.encode(buffer);
    buffer.flip();
    assertEquals("Serialization count", 3, count);
    assertType(buffer, 16, 0);
    assertEquals("WeakAnd arity", 2, buffer.get());
    assertEquals("WeakAnd N", 100, buffer.getShort() & 0x3fff);
    assertEquals(0, buffer.get());
    assertWord(buffer, "a");
    assertWord(buffer, "b");
}
Also used : MarkerWordItem(com.yahoo.prelude.query.MarkerWordItem) WordItem(com.yahoo.prelude.query.WordItem) ByteBuffer(java.nio.ByteBuffer) WeakAndItem(com.yahoo.prelude.query.WeakAndItem) Test(org.junit.Test)

Example 88 with WordItem

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

the class ItemEncodingTestCase method testONearItemEncoding.

@Test
public void testONearItemEncoding() {
    WordItem a = new WordItem("a");
    WordItem b = new WordItem("b");
    NearItem onear = new ONearItem(7);
    onear.addItem(a);
    onear.addItem(b);
    ByteBuffer buffer = ByteBuffer.allocate(128);
    int count = onear.encode(buffer);
    buffer.flip();
    assertEquals("Serialization count", 3, count);
    assertType(buffer, 12, 0);
    assertEquals("Near arity", 2, buffer.get());
    assertEquals("Limit", 7, buffer.get());
    assertWord(buffer, "a");
    assertWord(buffer, "b");
}
Also used : ONearItem(com.yahoo.prelude.query.ONearItem) MarkerWordItem(com.yahoo.prelude.query.MarkerWordItem) WordItem(com.yahoo.prelude.query.WordItem) ONearItem(com.yahoo.prelude.query.ONearItem) NearItem(com.yahoo.prelude.query.NearItem) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 89 with WordItem

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

the class NormalizingSearcherTestCase method testPhraseSegmentNormalization.

@Test
public void testPhraseSegmentNormalization() {
    Query query = new Query("/search?query=&search=cluster1&restrict=type1");
    PhraseSegmentItem phraseSegment = new PhraseSegmentItem("default", false, false);
    phraseSegment.addItem(new WordItem("net"));
    query.getModel().getQueryTree().setRoot(phraseSegment);
    assertEquals("'net'", query.getModel().getQueryTree().getRoot().toString());
    createExecution().search(query);
    assertEquals("'net'", query.getModel().getQueryTree().getRoot().toString());
}
Also used : Query(com.yahoo.search.Query) WordItem(com.yahoo.prelude.query.WordItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) Test(org.junit.Test)

Example 90 with WordItem

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

the class InputCheckingSearcher method countSingleCharacterUserTerms.

private int countSingleCharacterUserTerms(Item queryItem) {
    if (queryItem instanceof CompositeItem) {
        int sum = 0;
        CompositeItem asComposite = (CompositeItem) queryItem;
        for (ListIterator<Item> i = asComposite.getItemIterator(); i.hasNext(); ) {
            sum += countSingleCharacterUserTerms(i.next());
        }
        return sum;
    } else if (queryItem instanceof WordItem) {
        WordItem word = (WordItem) queryItem;
        return (word.isFromQuery() && word.stringValue().length() == 1) ? 1 : 0;
    } else {
        return 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) CompositeItem(com.yahoo.prelude.query.CompositeItem) WordItem(com.yahoo.prelude.query.WordItem)

Aggregations

WordItem (com.yahoo.prelude.query.WordItem)93 Test (org.junit.Test)76 AndItem (com.yahoo.prelude.query.AndItem)45 PhraseItem (com.yahoo.prelude.query.PhraseItem)31 Query (com.yahoo.search.Query)25 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)20 CompositeItem (com.yahoo.prelude.query.CompositeItem)18 Item (com.yahoo.prelude.query.Item)17 MarkerWordItem (com.yahoo.prelude.query.MarkerWordItem)16 NotItem (com.yahoo.prelude.query.NotItem)16 OrItem (com.yahoo.prelude.query.OrItem)13 ByteBuffer (java.nio.ByteBuffer)11 PrefixItem (com.yahoo.prelude.query.PrefixItem)10 SubstringItem (com.yahoo.prelude.query.SubstringItem)10 SuffixItem (com.yahoo.prelude.query.SuffixItem)10 Execution (com.yahoo.search.searchchain.Execution)10 RankItem (com.yahoo.prelude.query.RankItem)9 PhraseMatcher (com.yahoo.prelude.querytransform.PhraseMatcher)9 IntItem (com.yahoo.prelude.query.IntItem)8 WeakAndItem (com.yahoo.prelude.query.WeakAndItem)7