use of com.yahoo.prelude.IndexFacts in project vespa by vespa-engine.
the class StemmingSearcher method search.
@Override
public Result search(Query query, Execution execution) {
if (query.properties().getBoolean(DISABLE))
return execution.search(query);
IndexFacts.Session indexFacts = execution.context().getIndexFacts().newSession(query);
Item newRoot = replaceTerms(query, indexFacts);
query.getModel().getQueryTree().setRoot(newRoot);
query.trace(getFunctionName(), true, 2);
Highlight highlight = query.getPresentation().getHighlight();
if (highlight != null) {
Set<String> highlightFields = highlight.getHighlightItems().keySet();
for (String field : highlightFields) {
StemMode stemMode = indexFacts.getIndex(field).getStemMode();
if (stemMode != StemMode.NONE) {
Item newHighlight = scan(highlight.getHighlightItems().get(field), false, Language.ENGLISH, indexFacts, null);
highlight.getHighlightItems().put(field, (AndItem) newHighlight);
}
}
}
return execution.search(query);
}
use of com.yahoo.prelude.IndexFacts in project vespa by vespa-engine.
the class QueryMarshallerTestCase method testQueryString.
private void testQueryString(QueryMarshaller marshaller, String uq, String mq, String lang, Linguistics linguistics) {
Query query = new Query("/?query=" + QueryTestCase.httpEncode(uq) + ((lang != null) ? "&language=" + lang : ""));
query.getModel().setExecution(new Execution(new Execution.Context(null, new IndexFacts(), null, null, linguistics)));
assertEquals(mq, marshaller.marshal(query.getModel().getQueryTree().getRoot()));
}
use of com.yahoo.prelude.IndexFacts in project vespa by vespa-engine.
the class JuniperSearcherTestCase method createExecution.
private Execution createExecution(Chain<Searcher> chain) {
Map<String, List<String>> clusters = new LinkedHashMap<>();
Map<String, SearchDefinition> searchDefs = new LinkedHashMap<>();
searchDefs.put("one", createSearchDefinitionOne());
searchDefs.put("two", createSearchDefinitionTwo());
SearchDefinition union = new SearchDefinition("union");
IndexModel indexModel = new IndexModel(clusters, searchDefs, union);
return new Execution(chain, Execution.Context.createContextStub(new IndexFacts(indexModel)));
}
use of com.yahoo.prelude.IndexFacts in project vespa by vespa-engine.
the class RecallSearcherTestCase method assertQueryTree.
private static void assertQueryTree(String query, List<String> ranked, List<String> unranked) {
RecallSearcher searcher = new RecallSearcher();
Query obj = new Query(query);
Result result = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())).search(obj);
if (result.hits().getError() != null) {
fail(result.hits().getError().toString());
}
List<String> myRanked = new ArrayList<>(ranked);
List<String> myUnranked = new ArrayList<>(unranked);
Stack<Item> stack = new Stack<>();
stack.push(obj.getModel().getQueryTree().getRoot());
while (!stack.isEmpty()) {
Item item = stack.pop();
if (item instanceof WordItem) {
String word = ((WordItem) item).getWord();
if (item.isRanked()) {
int idx = myRanked.indexOf(word);
if (idx < 0) {
fail("Term '" + word + "' not expected as ranked term.");
}
myRanked.remove(idx);
} else {
int idx = myUnranked.indexOf(word);
if (idx < 0) {
fail("Term '" + word + "' not expected as unranked term.");
}
myUnranked.remove(idx);
}
}
if (item instanceof CompositeItem) {
CompositeItem lst = (CompositeItem) item;
for (Iterator<?> it = lst.getItemIterator(); it.hasNext(); ) {
stack.push((Item) it.next());
}
}
}
if (!myRanked.isEmpty()) {
fail("Ranked terms " + myRanked + " not found.");
}
if (!myUnranked.isEmpty()) {
fail("Unranked terms " + myUnranked + " not found.");
}
}
use of com.yahoo.prelude.IndexFacts in project vespa by vespa-engine.
the class RecallSearcherTestCase method testDenyRankItems.
@Test
public void testDenyRankItems() {
RecallSearcher searcher = new RecallSearcher();
Query query = new Query("?recall=foo");
Result result = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())).search(query);
assertNotNull(result.hits().getError());
}
Aggregations