Search in sources :

Example 36 with IndexFacts

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

the class LegacyCombinatorTestCase method testNotCombinatorWithoutRoot.

public void testNotCombinatorWithoutRoot() {
    Query q = new Query("?query.juhu=b&query.juhu.defidx=nalle&query.juhu.operator=not");
    Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts()));
    e.search(q);
    assertEquals("NULL", q.getModel().getQueryTree().toString());
    assertTrue("No expected error found.", q.errors().size() > 0);
    System.out.println(q.errors());
    assertEquals("Did not get invalid query parameter error as expected.", Error.INVALID_QUERY_PARAMETER.code, q.errors().get(0).getCode());
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) IndexFacts(com.yahoo.prelude.IndexFacts)

Example 37 with IndexFacts

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

the class NGramSearcherTestCase method getMixedSetup.

private IndexFacts getMixedSetup() {
    IndexFacts indexFacts = new IndexFacts();
    String musicDoctype = "music";
    String songDoctype = "song";
    Index musicDefault = new Index("default");
    musicDefault.setNGram(true, 1);
    indexFacts.addIndex(musicDoctype, musicDefault);
    Index songDefault = new Index("default");
    indexFacts.addIndex(songDoctype, songDefault);
    Map<String, List<String>> clusters = new HashMap<>();
    clusters.put("musicOnly", Arrays.asList(new String[] { musicDoctype }));
    clusters.put("songOnly", Arrays.asList(new String[] { songDoctype }));
    clusters.put("musicAndSong", Arrays.asList(new String[] { musicDoctype, songDoctype }));
    indexFacts.setClusters(clusters);
    return indexFacts;
}
Also used : IndexFacts(com.yahoo.prelude.IndexFacts) HashMap(java.util.HashMap) Index(com.yahoo.prelude.Index) List(java.util.List) XMLString(com.yahoo.prelude.hitfield.XMLString) JSONString(com.yahoo.prelude.hitfield.JSONString)

Example 38 with IndexFacts

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

the class NGramSearcherTestCase method setUp.

@Override
public void setUp() {
    searcher = new NGramSearcher(new SimpleLinguistics());
    indexFacts = new IndexFacts();
    Index defaultIndex = new Index("default");
    defaultIndex.setNGram(true, 3);
    defaultIndex.setDynamicSummary(true);
    indexFacts.addIndex("default", defaultIndex);
    Index test = new Index("test");
    test.setHighlightSummary(true);
    indexFacts.addIndex("default", test);
    Index gram2 = new Index("gram2");
    gram2.setNGram(true, 2);
    gram2.setDynamicSummary(true);
    indexFacts.addIndex("default", gram2);
    Index gram3 = new Index("gram3");
    gram3.setNGram(true, 3);
    gram3.setHighlightSummary(true);
    indexFacts.addIndex("default", gram3);
    Index gram14 = new Index("gram14");
    gram14.setNGram(true, 14);
    gram14.setDynamicSummary(true);
    indexFacts.addIndex("default", gram14);
}
Also used : SimpleLinguistics(com.yahoo.language.simple.SimpleLinguistics) IndexFacts(com.yahoo.prelude.IndexFacts) Index(com.yahoo.prelude.Index) NGramSearcher(com.yahoo.search.querytransform.NGramSearcher)

Example 39 with IndexFacts

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

the class QueryTestCase method assertDetectionText.

private void assertDetectionText(String expectedDetectionText, String queryString, String... indexSpecs) {
    Query q = new Query(httpEncode("/?query=" + queryString));
    IndexFacts indexFacts = new IndexFacts();
    for (String indexSpec : indexSpecs) {
        String[] specParts = indexSpec.split(":");
        Index tokenIndex = new Index(specParts[1]);
        if (specParts[0].equals("text"))
            tokenIndex.setPlainTokens(true);
        indexFacts.addIndex("testSearchDefinition", tokenIndex);
    }
    MockLinguistics mockLinguistics = new MockLinguistics();
    q.getModel().setExecution(new Execution(Execution.Context.createContextStub(null, indexFacts, mockLinguistics)));
    // cause parsing
    q.getModel().getQueryTree();
    assertEquals(expectedDetectionText, mockLinguistics.detector.lastDetectionText);
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) IndexFacts(com.yahoo.prelude.IndexFacts) Index(com.yahoo.prelude.Index) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 40 with IndexFacts

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

the class QueryCombinator method addAndItems.

private void addAndItems(Query query, Iterable<QueryPart> pieces, Execution.Context context) {
    IndexFacts indexFacts = context.getIndexFacts();
    IndexFacts.Session session = indexFacts.newSession(query);
    Set<String> usedSources = new HashSet<>(session.documentTypes());
    Language language = query.getModel().getParsingLanguage();
    for (QueryPart part : pieces) {
        String defaultIndex;
        Item item = null;
        Index index = session.getIndex(part.defaultIndex);
        if (index == Index.nullIndex) {
            defaultIndex = null;
        } else {
            defaultIndex = part.defaultIndex;
        }
        try {
            CustomParser parser = (CustomParser) ParserFactory.newInstance(query.getModel().getType(), ParserEnvironment.fromExecutionContext(context));
            item = parser.parse(part.query, null, language, usedSources, indexFacts, defaultIndex);
        } catch (RuntimeException e) {
            String err = Exceptions.toMessageString(e);
            query.trace("Query parser threw an exception: " + err, true, 1);
            getLogger().log(LogLevel.WARNING, "Query parser threw exception searcher QueryCombinator for " + query.getHttpRequest().toString() + ", query part " + part.query + ": " + err);
        }
        if (item == null) {
            continue;
        }
        if (defaultIndex == null) {
            assignDefaultIndex(item, part.defaultIndex);
        }
        addAndItem(query.getModel().getQueryTree(), item);
    }
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) NullItem(com.yahoo.prelude.query.NullItem) IndexedItem(com.yahoo.prelude.query.IndexedItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) IndexFacts(com.yahoo.prelude.IndexFacts) Language(com.yahoo.language.Language) Index(com.yahoo.prelude.Index) CustomParser(com.yahoo.prelude.query.parser.CustomParser) HashSet(java.util.HashSet)

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