Search in sources :

Example 41 with IndexFacts

use of com.yahoo.prelude.IndexFacts in project vespa by vespa-engine.

the class DefaultPositionSearcher method search.

@Override
public com.yahoo.search.Result search(Query query, Execution execution) {
    Location location = query.getRanking().getLocation();
    if (location != null && (location.getAttribute() == null)) {
        IndexFacts facts = execution.context().getIndexFacts();
        List<String> search = facts.newSession(query.getModel().getSources(), query.getModel().getRestrict()).documentTypes();
        for (String sd : search) {
            String defaultPosition = facts.getDefaultPosition(sd);
            if (defaultPosition != null) {
                location.setAttribute(defaultPosition);
            }
        }
        if (location.getAttribute() == null) {
            location.setAttribute(facts.getDefaultPosition(null));
        }
    }
    return execution.search(query);
}
Also used : IndexFacts(com.yahoo.prelude.IndexFacts) Location(com.yahoo.prelude.Location)

Example 42 with IndexFacts

use of com.yahoo.prelude.IndexFacts in project vespa by vespa-engine.

the class DuplicateSourceTestCase method testDuplicateSource.

@Test
public void testDuplicateSource() {
    // Set up a single cluster and chain (chain1), containing a MockBackendSearcher and having 2 doc types (doc1, doc2)
    MockBackendSearcher mockBackendSearcher = new MockBackendSearcher();
    SearchChainRegistry searchChains = new SearchChainRegistry();
    searchChains.register(new Chain<>("chain1", mockBackendSearcher));
    IndexFacts indexFacts = new IndexFacts();
    Map<String, List<String>> clusters = new HashMap<>();
    clusters.put("chain1", ImmutableList.of("doc1", "doc2"));
    indexFacts.setClusters(clusters);
    SearchChainResolver resolver = new SearchChainResolver.Builder().addSearchChain(new ComponentId("chain1"), ImmutableList.of("doc1", "doc2")).build();
    FederationSearcher searcher = new FederationSearcher(new ComponentId("test"), resolver);
    Result result = searcher.search(new Query("?query=test&sources=doc1%2cdoc2"), new Execution(Execution.Context.createContextStub(searchChains, indexFacts)));
    assertNull(result.hits().getError());
    assertEquals(1, mockBackendSearcher.getInvocationCount());
}
Also used : FederationSearcher(com.yahoo.search.federation.FederationSearcher) IndexFacts(com.yahoo.prelude.IndexFacts) Query(com.yahoo.search.Query) HashMap(java.util.HashMap) SearchChainResolver(com.yahoo.search.federation.sourceref.SearchChainResolver) Result(com.yahoo.search.Result) Execution(com.yahoo.search.searchchain.Execution) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) SearchChainRegistry(com.yahoo.search.searchchain.SearchChainRegistry) ComponentId(com.yahoo.component.ComponentId) Test(org.junit.Test)

Example 43 with IndexFacts

use of com.yahoo.prelude.IndexFacts in project vespa by vespa-engine.

the class ValidatePredicateSearcherTestCase method doSearch.

private static Result doSearch(ValidatePredicateSearcher searcher, String yqlQuery, String command) {
    QueryTree queryTree = new YqlParser(new ParserEnvironment()).parse(new Parsable().setQuery(yqlQuery));
    Query query = new Query();
    query.getModel().getQueryTree().setRoot(queryTree.getRoot());
    TreeMap<String, List<String>> masterClusters = new TreeMap<>();
    masterClusters.put("cluster", Arrays.asList("document"));
    SearchDefinition searchDefinition = new SearchDefinition("document");
    Index index = new Index("predicate_field");
    index.addCommand(command);
    searchDefinition.addIndex(index);
    Map<String, SearchDefinition> searchDefinitionMap = new HashMap<>();
    searchDefinitionMap.put("document", searchDefinition);
    IndexFacts indexFacts = new IndexFacts(new IndexModel(masterClusters, searchDefinitionMap, searchDefinition));
    Execution.Context context = new Execution.Context(null, indexFacts, null, new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics());
    return new Execution(searcher, context).search(query);
}
Also used : Query(com.yahoo.search.Query) IndexFacts(com.yahoo.prelude.IndexFacts) Parsable(com.yahoo.search.query.parser.Parsable) Index(com.yahoo.prelude.Index) IndexModel(com.yahoo.prelude.IndexModel) SearchDefinition(com.yahoo.prelude.SearchDefinition) SimpleLinguistics(com.yahoo.language.simple.SimpleLinguistics) YqlParser(com.yahoo.search.yql.YqlParser) Execution(com.yahoo.search.searchchain.Execution) QueryTree(com.yahoo.search.query.QueryTree) RendererRegistry(com.yahoo.search.rendering.RendererRegistry) ParserEnvironment(com.yahoo.search.query.parser.ParserEnvironment)

Example 44 with IndexFacts

use of com.yahoo.prelude.IndexFacts in project vespa by vespa-engine.

the class SourceRefResolverTestCase method setupIndexFacts.

private static void setupIndexFacts() {
    TreeMap<String, List<String>> masterClusters = new TreeMap<>();
    masterClusters.put(cluster1, Arrays.asList("document1", "document2"));
    masterClusters.put(cluster2, Arrays.asList("document1"));
    masterClusters.put(cluster3, Arrays.asList("document3"));
    indexFacts = new IndexFacts(new IndexModel(masterClusters, null, null));
}
Also used : IndexFacts(com.yahoo.prelude.IndexFacts) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) IndexModel(com.yahoo.prelude.IndexModel)

Example 45 with IndexFacts

use of com.yahoo.prelude.IndexFacts in project vespa by vespa-engine.

the class LiteralBoostSearcherTestCase method createIndexFacts.

private IndexFacts createIndexFacts() {
    Map<String, List<String>> clusters = new LinkedHashMap<>();
    clusters.put("cluster1", Arrays.asList("type1", "type2", "type3"));
    clusters.put("cluster2", Arrays.asList("type4", "type5"));
    Map<String, SearchDefinition> searchDefs = new LinkedHashMap<>();
    searchDefs.put("type1", createSearchDefinitionWithFields("type1", true));
    searchDefs.put("type2", createSearchDefinitionWithFields("type2", false));
    searchDefs.put("type3", new SearchDefinition("type3"));
    searchDefs.put("type3", new SearchDefinition("type3"));
    searchDefs.put("type4", new SearchDefinition("type4"));
    searchDefs.put("type5", new SearchDefinition("type5"));
    SearchDefinition union = new SearchDefinition("union");
    return new IndexFacts(new IndexModel(clusters, searchDefs, union));
}
Also used : IndexFacts(com.yahoo.prelude.IndexFacts) List(java.util.List) IndexModel(com.yahoo.prelude.IndexModel) LinkedHashMap(java.util.LinkedHashMap) SearchDefinition(com.yahoo.prelude.SearchDefinition)

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