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");
}
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;
}
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;
}
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());
}
}
}
}
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);
}
Aggregations