Search in sources :

Example 1 with Query

use of com.yahoo.search.Query in project vespa by vespa-engine.

the class ApplicationTest method container_and_referenced_content.

/**
 * Tests that an application with search chains referencing a content cluster can be constructed.
 */
@Test
public void container_and_referenced_content() throws Exception {
    try (Application application = Application.fromApplicationPackage(new File("src/test/app-packages/withcontent"), Networking.disable)) {
        Result result = application.getJDisc("default").search().process(new ComponentSpecification("default"), new Query("?query=substring:foobar&tracelevel=3"));
        assertEquals("AND substring:fo substring:oo substring:ob substring:ba substring:ar", result.hits().get("hasQuery").getQuery().getModel().getQueryTree().toString());
    }
}
Also used : Query(com.yahoo.search.Query) ComponentSpecification(com.yahoo.component.ComponentSpecification) File(java.io.File) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 2 with Query

use of com.yahoo.search.Query in project vespa by vespa-engine.

the class ApplicationTest method search_default.

@Test
public void search_default() throws Exception {
    try (ApplicationFacade app = new ApplicationFacade(Application.fromBuilder(new Application.Builder().container("default", new Application.Builder.Container().searcher(MockSearcher.class))))) {
        Result result = app.search(new Query("?query=foo"));
        assertEquals(1, result.hits().size());
    }
}
Also used : MockSearcher(com.yahoo.application.container.searchers.MockSearcher) Query(com.yahoo.search.Query) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 3 with Query

use of com.yahoo.search.Query in project vespa by vespa-engine.

the class ApplicationTest method search.

@Test
public void search() throws Exception {
    try (ApplicationFacade app = new ApplicationFacade(Application.fromBuilder(new Application.Builder().container("default", new Application.Builder.Container().searcher("foo", MockSearcher.class))))) {
        Result result = app.search("foo", new Query("?query=foo"));
        assertEquals(1, result.hits().size());
    }
}
Also used : MockSearcher(com.yahoo.application.container.searchers.MockSearcher) Query(com.yahoo.search.Query) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 4 with Query

use of com.yahoo.search.Query in project vespa by vespa-engine.

the class ClusterSearcher method searchMultipleDocumentTypes.

private Result searchMultipleDocumentTypes(Searcher searcher, Query query, Execution execution) {
    Set<String> docTypes = resolveDocumentTypes(query, execution.context().getIndexFacts());
    Result invalidRankProfile = checkValidRankProfiles(query, docTypes);
    if (invalidRankProfile != null) {
        return invalidRankProfile;
    }
    List<Query> queries = createQueries(query, docTypes);
    if (queries.size() == 1) {
        return searcher.search(queries.get(0), execution);
    } else {
        Result mergedResult = new Result(query.clone());
        for (Query q : queries) {
            Result result = searcher.search(q, execution);
            mergedResult.mergeWith(result);
            mergedResult.hits().addAll(result.hits().asUnorderedHits());
        }
        // Should we trim the merged result?
        if (query.getOffset() > 0 || query.getHits() < mergedResult.hits().size()) {
            if (mergedResult.getHitOrderer() != null) {
                // Make sure we have the necessary data for sorting
                searcher.fill(mergedResult, Execution.ATTRIBUTEPREFETCH, execution);
            }
            mergedResult.hits().trim(query.getOffset(), query.getHits());
        }
        return mergedResult;
    }
}
Also used : Query(com.yahoo.search.Query) Result(com.yahoo.search.Result)

Example 5 with Query

use of com.yahoo.search.Query in project vespa by vespa-engine.

the class PacketQueryTracer method addTrace.

private void addTrace(FS4Channel channel, BasicPacket packet, ByteBuffer serializedForm) {
    Query query = channel.getQuery();
    if (query != null && query.getTraceLevel() >= traceLevel) {
        StringBuilder traceString = new StringBuilder();
        traceString.append(packet.getClass().getSimpleName()).append(": ");
        hexDump(serializedForm, traceString);
        final boolean includeQuery = true;
        query.trace(traceString.toString(), includeQuery, traceLevel);
    }
}
Also used : Query(com.yahoo.search.Query)

Aggregations

Query (com.yahoo.search.Query)689 Test (org.junit.Test)415 Result (com.yahoo.search.Result)229 Execution (com.yahoo.search.searchchain.Execution)184 Searcher (com.yahoo.search.Searcher)82 QueryProfile (com.yahoo.search.query.profile.QueryProfile)63 Hit (com.yahoo.search.result.Hit)52 Chain (com.yahoo.component.chain.Chain)47 IndexFacts (com.yahoo.prelude.IndexFacts)44 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)37 AndItem (com.yahoo.prelude.query.AndItem)33 WordItem (com.yahoo.prelude.query.WordItem)33 FastHit (com.yahoo.prelude.fastsearch.FastHit)31 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)27 HitGroup (com.yahoo.search.result.HitGroup)24 Item (com.yahoo.prelude.query.Item)21 HashMap (java.util.HashMap)20 CacheKey (com.yahoo.prelude.fastsearch.CacheKey)18 GroupingRequest (com.yahoo.search.grouping.GroupingRequest)18 ArrayList (java.util.ArrayList)18