Search in sources :

Example 61 with Item

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

the class QueryTestCase method testPositiveTerms.

@Test
public void testPositiveTerms() {
    Query q = new Query(httpEncode("/?query=-a \"b c\" d e"));
    Item i = q.getModel().getQueryTree().getRoot();
    List<IndexedItem> l = QueryTree.getPositiveTerms(i);
    assertEquals(3, l.size());
}
Also used : OrItem(com.yahoo.prelude.query.OrItem) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) IndexedItem(com.yahoo.prelude.query.IndexedItem) Item(com.yahoo.prelude.query.Item) WordItem(com.yahoo.prelude.query.WordItem) Query(com.yahoo.search.Query) IndexedItem(com.yahoo.prelude.query.IndexedItem) Test(org.junit.Test)

Example 62 with Item

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

the class YqlParserTestCase method testRegexp.

@Test
public void testRegexp() {
    QueryTree x = parse("select * from sources * where foo matches \"a b\";");
    Item root = x.getRoot();
    assertSame(RegExpItem.class, root.getClass());
    assertEquals("a b", ((RegExpItem) root).stringValue());
}
Also used : WordAlternativesItem(com.yahoo.prelude.query.WordAlternativesItem) ExactStringItem(com.yahoo.prelude.query.ExactStringItem) WeakAndItem(com.yahoo.prelude.query.WeakAndItem) IndexedItem(com.yahoo.prelude.query.IndexedItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) RegExpItem(com.yahoo.prelude.query.RegExpItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) QueryTree(com.yahoo.search.query.QueryTree) Test(org.junit.Test)

Example 63 with Item

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

the class VespaBackEndSearcher method search.

public Result search(Query query, Execution execution) {
    // query root should not be null here
    Item root = query.getModel().getQueryTree().getRoot();
    if (root == null || root instanceof NullItem) {
        return new Result(query, ErrorMessage.createNullQuery(query.getHttpRequest().getUri().toString()));
    }
    if (wantsRPCSummaryFill(query) && summaryNeedsQuery(query)) {
        return new Result(query, ErrorMessage.createInvalidQueryParameter("When using dispatch.summaries and your summary/rankprofile require the query, " + " you need to enable ranking.queryCache."));
    }
    QueryRewrite.optimizeByRestrict(query);
    QueryRewrite.optimizeAndNot(query);
    QueryRewrite.collapseSingleComposites(query);
    root = query.getModel().getQueryTree().getRoot();
    if (// root can become null after optimization
    root == null || root instanceof NullItem)
        return new Result(query);
    resolveDocumentDatabase(query);
    transformQuery(query);
    traceQuery(name, "search", query, query.getOffset(), query.getHits(), 1, Optional.empty());
    root = query.getModel().getQueryTree().getRoot();
    if (// root can become null after resolving and transformation?
    root == null || root instanceof NullItem)
        return new Result(query);
    QueryPacket queryPacket = QueryPacket.create(query);
    int compressionLimit = query.properties().getInteger(PACKET_COMPRESSION_LIMIT, 0);
    queryPacket.setCompressionLimit(compressionLimit);
    if (compressionLimit != 0)
        queryPacket.setCompressionType(query.properties().getString(PACKET_COMPRESSION_TYPE, "lz4"));
    if (isLoggingFine())
        getLogger().fine("made QueryPacket: " + queryPacket);
    Result result = null;
    CacheKey cacheKey = null;
    if (cacheControl.useCache(query)) {
        cacheKey = new CacheKey(queryPacket);
        result = getCached(cacheKey, queryPacket.getQueryPacketData(), query);
    }
    if (result == null) {
        result = doSearch2(query, queryPacket, cacheKey, execution);
        if (isLoggingFine())
            getLogger().fine("Result NOT retrieved from cache");
        if (query.getTraceLevel() >= 1)
            query.trace(getName() + " dispatch response: " + result, false, 1);
        result.trace(getName());
    }
    return result;
}
Also used : NullItem(com.yahoo.prelude.query.NullItem) Item(com.yahoo.prelude.query.Item) NullItem(com.yahoo.prelude.query.NullItem) QueryPacket(com.yahoo.fs4.QueryPacket) Result(com.yahoo.search.Result)

Example 64 with Item

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

the class LiteralBoostSearcher method addTopLevelRankTerms.

/**
 * Adds a RankItem at the root of a query, but only if there is
 * at least one rank term in the specified RankItem.
 * If the root is already a RankItem, just append the new rank terms.
 *
 * @param rankTerms the new rank item to add.
 * @param query the query to add to
 */
private void addTopLevelRankTerms(RankItem rankTerms, Query query) {
    Item root = query.getModel().getQueryTree().getRoot();
    if (root instanceof RankItem) {
        for (Iterator<Item> i = rankTerms.getItemIterator(); i.hasNext(); ) {
            ((RankItem) root).addItem(i.next());
        }
    } else {
        rankTerms.addItem(0, root);
        query.getModel().getQueryTree().setRoot(rankTerms);
    }
}
Also used : TermItem(com.yahoo.prelude.query.TermItem) CompositeItem(com.yahoo.prelude.query.CompositeItem) Item(com.yahoo.prelude.query.Item) RankItem(com.yahoo.prelude.query.RankItem) WordItem(com.yahoo.prelude.query.WordItem) NotItem(com.yahoo.prelude.query.NotItem) RankItem(com.yahoo.prelude.query.RankItem)

Example 65 with Item

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

the class QueryRewrite method extractAndNotRecursively.

private static CompositeItem extractAndNotRecursively(CompositeItem parent) {
    for (int i = 0; i < parent.getItemCount(); i++) {
        Item child = parent.getItem(i);
        Item possibleNewChild = optimizeAndNot(child);
        if (child != possibleNewChild) {
            parent.setItem(i, possibleNewChild);
        }
    }
    if (parent instanceof AndItem) {
        return extractAndNot((AndItem) parent);
    }
    return parent;
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) NullItem(com.yahoo.prelude.query.NullItem) SimpleIndexedItem(com.yahoo.prelude.query.SimpleIndexedItem) OrItem(com.yahoo.prelude.query.OrItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) NotItem(com.yahoo.prelude.query.NotItem) NearItem(com.yahoo.prelude.query.NearItem) EquivItem(com.yahoo.prelude.query.EquivItem) AndItem(com.yahoo.prelude.query.AndItem)

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