Search in sources :

Example 1 with WordItem

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

use of com.yahoo.prelude.query.WordItem 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 3 with WordItem

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

the class FastSearcherTestCase method testSinglePhaseCachedSupersets.

@Ignore
public void testSinglePhaseCachedSupersets() {
    Logger.getLogger(FastSearcher.class.getName()).setLevel(Level.ALL);
    MockFSChannel.resetDocstamp();
    FastSearcher fastSearcher = new FastSearcher(new MockBackend(), new FS4ResourcePool(1), new MockDispatcher(Collections.emptyList()), new SummaryParameters(null), new ClusterParams("testhittype"), new CacheParams(100, 1e64), documentdbInfoConfig);
    CacheControl c = fastSearcher.getCacheControl();
    Result result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 2);
    Query q = new Query("?query=ignored");
    ((WordItem) q.getModel().getQueryTree().getRoot()).setUniqueID(1);
    QueryPacket queryPacket = QueryPacket.create(q);
    CacheKey k = new CacheKey(queryPacket);
    PacketWrapper p = c.lookup(k, q);
    assertEquals(1, p.getResultPackets().size());
    result = doSearch(fastSearcher, new Query("?query=ignored"), 1, 1);
    p = c.lookup(k, q);
    // ensure we don't get redundant QueryResultPacket instances
    // in the cache
    assertEquals(1, p.getResultPackets().size());
    assertEquals(1, result.getConcreteHitCount());
    for (int i = 0; i < result.getHitCount(); i++) {
        assertTrue(result.hits().get(i).isCached());
    }
    result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 1);
    p = c.lookup(k, q);
    assertEquals(1, p.getResultPackets().size());
    assertEquals(1, result.getConcreteHitCount());
    for (int i = 0; i < result.getHitCount(); i++) {
        assertTrue(result.hits().get(i).isCached());
    }
}
Also used : Query(com.yahoo.search.Query) Result(com.yahoo.search.Result) MockBackend(com.yahoo.prelude.fastsearch.test.fs4mock.MockBackend) WordItem(com.yahoo.prelude.query.WordItem) Ignore(org.junit.Ignore)

Example 4 with WordItem

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

the class GetRawWordTestCase method testGetRawWord.

@Test
public void testGetRawWord() {
    Query query = new Query("?query=%C4%B0%C5%9EBANKASI%20GAZ%C4%B0EM%C4%B0R&searchChain=vespa");
    assertEquals("AND \u0130\u015EBANKASI GAZ\u0130EM\u0130R", query.getModel().getQueryTree().toString());
    AndItem root = (AndItem) query.getModel().getQueryTree().getRoot();
    {
        WordItem word = (WordItem) root.getItem(0);
        assertEquals("\u0130\u015EBANKASI", word.getRawWord());
        assertEquals(0, word.getOrigin().start);
        assertEquals(9, word.getOrigin().end);
    }
    {
        WordItem word = (WordItem) root.getItem(1);
        assertEquals("GAZ\u0130EM\u0130R", word.getRawWord());
        assertEquals(10, word.getOrigin().start);
        assertEquals(18, word.getOrigin().end);
    }
    assertEquals("Total string is just these words", 18, ((WordItem) root.getItem(0)).getOrigin().getSuperstring().length());
}
Also used : Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) Test(org.junit.Test)

Example 5 with WordItem

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

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