Search in sources :

Example 11 with Query

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

the class RuleBaseBenchmark method benchmark.

public void benchmark(String ruleBaseFile, String queryFile, int iterations) throws IOException, ParseException {
    String fsaFile = null;
    if (ruleBaseFile.endsWith(".sr")) {
        fsaFile = ruleBaseFile.substring(0, ruleBaseFile.length() - 3) + ".fsa";
        File fsa = new File(fsaFile);
        if (!fsa.exists()) {
            fsaFile = null;
        }
    }
    RuleBase ruleBase = new RuleImporter().importFile(ruleBaseFile, fsaFile);
    ArrayList<String> queries = new ArrayList<>();
    BufferedReader reader = new BufferedReader(new FileReader(queryFile));
    String line;
    while ((line = reader.readLine()) != null) {
        queries.add(line);
    }
    Date start = new Date();
    for (int i = 0; i < iterations; i++) {
        for (Iterator<String> iter = queries.iterator(); iter.hasNext(); ) {
            String queryString = iter.next();
            Query query = new Query("?query=" + queryString);
            ruleBase.analyze(query, 0);
        }
    }
    Date end = new Date();
    long elapsed = end.getTime() - start.getTime();
    System.out.print("BENCHMARK: rulebase=" + ruleBaseFile + "\n           fsa=" + fsaFile + "\n           queries=" + queryFile + "\n           iterations=" + iterations + "\n           elapsed=" + elapsed + "ms\n");
}
Also used : Query(com.yahoo.search.Query) ArrayList(java.util.ArrayList) Date(java.util.Date) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) RuleImporter(com.yahoo.prelude.semantics.RuleImporter) File(java.io.File) RuleBase(com.yahoo.prelude.semantics.RuleBase)

Example 12 with Query

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

the class CachingSearcher method search.

public Result search(com.yahoo.search.Query query, Execution execution) {
    if (query.getNoCache()) {
        return execution.search(query);
    }
    QueryCacheKey queryKey = new QueryCacheKey(query);
    Result cachedResult = cache.get(queryKey);
    if (cachedResult != null) {
        cacheHit();
        return cachedResult;
    }
    cacheMiss();
    // Need a copy, as cache hash key later on, maybe.
    Query originalQuery = query.clone();
    Result result = execution.search(query);
    execution.fill(result);
    if (!noCacheWrite(query)) {
        // Because the query member has changed state
        queryKey.setQuery(originalQuery);
        cache.put(queryKey, result);
    }
    return result;
}
Also used : Query(com.yahoo.search.Query) QueryCacheKey(com.yahoo.prelude.cache.QueryCacheKey) Result(com.yahoo.search.Result)

Example 13 with Query

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

the class ParameterNameSpace method matches.

public boolean matches(String term, RuleEvaluation e) {
    Query query = e.getEvaluation().getQuery();
    String value = query.properties().getString(term);
    if (value == null)
        return false;
    e.setValue(value);
    return true;
}
Also used : Query(com.yahoo.search.Query)

Example 14 with Query

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

the class FederationSearcher method fill.

@Override
public void fill(Result result, String summaryClass, Execution execution) {
    UniqueExecutionsToResults uniqueExecutionsToResults = new UniqueExecutionsToResults();
    addResultsToFill(result.hits(), result, summaryClass, uniqueExecutionsToResults);
    Set<Entry<Chain<Searcher>, Map<Query, Result>>> resultsForAllChains = uniqueExecutionsToResults.resultsToFill.entrySet();
    int numberOfCallsToFillNeeded = 0;
    for (Entry<Chain<Searcher>, Map<Query, Result>> resultsToFillForAChain : resultsForAllChains) {
        numberOfCallsToFillNeeded += resultsToFillForAChain.getValue().size();
    }
    List<Pair<Result, FutureResult>> futureFilledResults = new ArrayList<>();
    for (Entry<Chain<Searcher>, Map<Query, Result>> resultsToFillForAChain : resultsForAllChains) {
        Chain<Searcher> chain = resultsToFillForAChain.getKey();
        Execution chainExecution = (chain == null) ? execution : new Execution(chain, execution.context());
        for (Entry<Query, Result> resultsToFillForAChainAndQuery : resultsToFillForAChain.getValue().entrySet()) {
            Result resultToFill = resultsToFillForAChainAndQuery.getValue();
            if (numberOfCallsToFillNeeded == 1) {
                chainExecution.fill(resultToFill, summaryClass);
                propagateErrors(resultToFill, result);
            } else {
                AsyncExecution asyncFill = new AsyncExecution(chainExecution);
                futureFilledResults.add(new Pair<>(resultToFill, asyncFill.fill(resultToFill, summaryClass)));
            }
        }
    }
    for (Pair<Result, FutureResult> futureFilledResult : futureFilledResults) {
        // futureFilledResult is a pair of a result to be filled and the future in which that same result is filled
        Optional<Result> filledResult = futureFilledResult.getSecond().getIfAvailable(result.getQuery().getTimeLeft(), TimeUnit.MILLISECONDS);
        if (filledResult.isPresent()) {
            // fill completed
            propagateErrors(filledResult.get(), result);
        } else {
            // fill timed out: Remove these hits as they are incomplete and may cause a race when accessed later
            result.hits().addError(futureFilledResult.getSecond().createTimeoutError());
            for (Iterator<Hit> i = futureFilledResult.getFirst().hits().unorderedDeepIterator(); i.hasNext(); ) {
                // Note that some of these hits may be filled, but as the fill thread may still be working on them
                // and we do not synchronize with it we need to discard all
                Hit removed = result.hits().remove(i.next().getId());
            }
        }
    }
}
Also used : Chain(com.yahoo.component.chain.Chain) Query(com.yahoo.search.Query) AsyncExecution(com.yahoo.search.searchchain.AsyncExecution) Searcher(com.yahoo.search.Searcher) ForkingSearcher(com.yahoo.search.searchchain.ForkingSearcher) ArrayList(java.util.ArrayList) Result(com.yahoo.search.Result) FutureResult(com.yahoo.search.searchchain.FutureResult) Entry(java.util.Map.Entry) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) AsyncExecution(com.yahoo.search.searchchain.AsyncExecution) FutureResult(com.yahoo.search.searchchain.FutureResult) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) CopyOnWriteHashMap(com.yahoo.concurrent.CopyOnWriteHashMap) Pair(com.yahoo.collections.Pair)

Example 15 with Query

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

the class FederationSearcher method getSearchChainGroup.

private Result getSearchChainGroup(Hit hit, Result result, UniqueExecutionsToResults uniqueExecutionsToResults) {
    @SuppressWarnings("unchecked") Chain<Searcher> chain = (Chain<Searcher>) hit.getSearcherSpecificMetaData(this);
    Query query = hit.getQuery() != null ? hit.getQuery() : result.getQuery();
    return uniqueExecutionsToResults.get(chain, query);
}
Also used : Chain(com.yahoo.component.chain.Chain) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) ForkingSearcher(com.yahoo.search.searchchain.ForkingSearcher)

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