use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.
the class ParseTestCase method testPrefixExtraStar.
/**
* Extra star is ignored
*/
@Test
public void testPrefixExtraStar() {
Item root = tester.assertParsed("prefix*", "prefix**", Query.Type.ANY);
assertTrue(root instanceof PrefixItem);
}
use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.
the class LegacyCombinator method addRankItems.
private void addRankItems(Language language, Query query, Set<QueryPart> pieces, IndexFacts.Session session, Execution.Context context) {
for (QueryPart part : pieces) {
if (part.operator != Combinator.PREFERRED)
continue;
String defaultIndex = defaultIndex(session, part);
Item item = parse(language, query, part, defaultIndex, context);
if (item == null)
continue;
setDefaultIndex(part, defaultIndex, item);
addRankItem(query.getModel().getQueryTree(), item);
}
}
use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.
the class QueryTreeUtil method andQueryItemWithRoot.
public static void andQueryItemWithRoot(QueryTree tree, Item item) {
if (tree.isEmpty()) {
tree.setRoot(item);
} else {
Item oldRoot = tree.getRoot();
if (oldRoot.getClass() == AndItem.class) {
((AndItem) oldRoot).addItem(item);
} else {
AndItem newRoot = new AndItem();
newRoot.addItem(oldRoot);
newRoot.addItem(item);
tree.setRoot(newRoot);
}
}
}
use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.
the class GroupingExecutor method performSearch.
/**
* Performs the actual search passes to complete all the given {@link Grouping} requests. This method uses the
* grouping map argument as both an input and an output variable, as the contained {@link Grouping} objects are
* updates as results arrive from the back end.
*
* @param query The query to execute.
* @param execution The execution context used to run the queries.
* @param groupingMap The map of grouping requests to perform.
* @return The search result to pass back from this searcher.
*/
private Result performSearch(Query query, Execution execution, Map<Integer, Grouping> groupingMap) {
// Determine how many passes to perform.
int lastPass = 0;
for (Grouping grouping : groupingMap.values()) {
if (!grouping.useSinglePass()) {
lastPass = Math.max(lastPass, grouping.getLevels().size());
}
}
// Perform multi-pass query to complete all grouping requests.
Item origRoot = query.getModel().getQueryTree().getRoot();
int prePassErrors = query.errors().size();
Result ret = null;
Item baseRoot = origRoot;
if (lastPass > 0) {
baseRoot = origRoot.clone();
}
if (query.isTraceable(3) && query.getGroupingSessionCache()) {
query.trace("Grouping in " + (lastPass + 1) + " passes. SessionId='" + query.getSessionId(true) + "'.", 3);
}
for (int pass = 0; pass <= lastPass; ++pass) {
boolean firstPass = (pass == 0);
List<Grouping> passList = getGroupingListForPassN(groupingMap, pass);
if (passList.isEmpty()) {
throw new RuntimeException("No grouping request for pass " + pass + ", bug!");
}
if (log.isLoggable(LogLevel.DEBUG)) {
for (Grouping grouping : passList) {
log.log(LogLevel.DEBUG, "Pass(" + pass + "), Grouping(" + grouping.getId() + "): " + grouping);
}
}
Item passRoot;
if (firstPass) {
// Use original query the first time.
passRoot = origRoot;
} else if (pass == lastPass) {
// Has already been cloned once, use this for last pass.
passRoot = baseRoot;
} else {
// noinspection ConstantConditions
passRoot = baseRoot.clone();
}
if (query.isTraceable(4) && query.getGroupingSessionCache()) {
query.trace("Grouping with session cache '" + query.getGroupingSessionCache() + "' enabled for pass #" + pass + ".", 4);
}
if (origRoot != passRoot) {
query.getModel().getQueryTree().setRoot(passRoot);
}
setGroupingList(query, passList);
Result passResult = execution.search(query);
if (passResult.hits().getError() != null) {
if (firstPass) {
if (passResult.hits().getErrorHit().errors().size() > prePassErrors || passResult.hits().getErrorHit().errors().size() == 0) {
return passResult;
}
} else {
return passResult;
}
}
Map<Integer, Grouping> passGroupingMap = mergeGroupingResults(passResult);
mergeGroupingMaps(groupingMap, passGroupingMap);
if (firstPass) {
ret = passResult;
}
}
if (log.isLoggable(LogLevel.DEBUG)) {
for (Grouping grouping : groupingMap.values()) {
log.log(LogLevel.DEBUG, "Result Grouping(" + grouping.getId() + "): " + grouping);
}
}
return ret;
}
use of com.yahoo.prelude.query.Item in project vespa by vespa-engine.
the class YqlParser method buildUserInput.
@NonNull
private Item buildUserInput(OperatorNode<ExpressionOperator> ast) {
// TODO add support for default arguments if property results in nothing
List<OperatorNode<ExpressionOperator>> args = ast.getArgument(1);
String wordData = getStringContents(args.get(0));
Boolean allowEmpty = getAnnotation(ast, USER_INPUT_ALLOW_EMPTY, Boolean.class, Boolean.FALSE, "flag for allowing NullItem to be returned");
if (allowEmpty && (wordData == null || wordData.isEmpty()))
return new NullItem();
String grammar = getAnnotation(ast, USER_INPUT_GRAMMAR, String.class, Query.Type.ALL.toString(), "grammar for handling user input");
String defaultIndex = getAnnotation(ast, USER_INPUT_DEFAULT_INDEX, String.class, "default", "default index for user input terms");
Language language = decideParsingLanguage(ast, wordData);
Item item;
if (USER_INPUT_RAW.equals(grammar)) {
item = instantiateWordItem(defaultIndex, wordData, ast, null, SegmentWhen.NEVER, true, language);
} else if (USER_INPUT_SEGMENT.equals(grammar)) {
item = instantiateWordItem(defaultIndex, wordData, ast, null, SegmentWhen.ALWAYS, false, language);
} else {
item = parseUserInput(grammar, defaultIndex, wordData, language, allowEmpty);
propagateUserInputAnnotations(ast, item);
}
return item;
}
Aggregations