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