Search in sources :

Example 1 with IndexFacts

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);
}
Also used : IndexFacts(com.yahoo.prelude.IndexFacts) StemMode(com.yahoo.language.process.StemMode)

Example 2 with IndexFacts

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()));
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) IndexFacts(com.yahoo.prelude.IndexFacts)

Example 3 with IndexFacts

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)));
}
Also used : Execution(com.yahoo.search.searchchain.Execution) IndexFacts(com.yahoo.prelude.IndexFacts) List(java.util.List) IndexModel(com.yahoo.prelude.IndexModel) LinkedHashMap(java.util.LinkedHashMap) SearchDefinition(com.yahoo.prelude.SearchDefinition)

Example 4 with IndexFacts

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.");
    }
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) Query(com.yahoo.search.Query) IndexFacts(com.yahoo.prelude.IndexFacts) RecallSearcher(com.yahoo.prelude.querytransform.RecallSearcher) ArrayList(java.util.ArrayList) Result(com.yahoo.search.Result) Stack(java.util.Stack) CompositeItem(com.yahoo.prelude.query.CompositeItem) NullItem(com.yahoo.prelude.query.NullItem) Item(com.yahoo.prelude.query.Item) WordItem(com.yahoo.prelude.query.WordItem) Execution(com.yahoo.search.searchchain.Execution) WordItem(com.yahoo.prelude.query.WordItem)

Example 5 with IndexFacts

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());
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) IndexFacts(com.yahoo.prelude.IndexFacts) RecallSearcher(com.yahoo.prelude.querytransform.RecallSearcher) Result(com.yahoo.search.Result) Test(org.junit.Test)

Aggregations

IndexFacts (com.yahoo.prelude.IndexFacts)73 Query (com.yahoo.search.Query)41 Execution (com.yahoo.search.searchchain.Execution)34 Test (org.junit.Test)26 Index (com.yahoo.prelude.Index)22 IndexModel (com.yahoo.prelude.IndexModel)12 Result (com.yahoo.search.Result)8 ArrayList (java.util.ArrayList)8 List (java.util.List)8 SimpleLinguistics (com.yahoo.language.simple.SimpleLinguistics)7 SearchDefinition (com.yahoo.prelude.SearchDefinition)6 IndexInfoConfig (com.yahoo.search.config.IndexInfoConfig)6 Chain (com.yahoo.component.chain.Chain)5 Token (com.yahoo.prelude.query.parser.Token)5 Tokenizer (com.yahoo.prelude.query.parser.Tokenizer)5 ConfigGetter (com.yahoo.config.subscription.ConfigGetter)4 AndItem (com.yahoo.prelude.query.AndItem)4 WordItem (com.yahoo.prelude.query.WordItem)4 HashSet (java.util.HashSet)4 LinkedHashMap (java.util.LinkedHashMap)4