Search in sources :

Example 51 with IndexFacts

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

the class QueryCombinatorTestCase method testMultiPart.

public void testMultiPart() {
    Query q = new Query("?query=a&query.juhu=b&query.nalle=c");
    Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts()));
    Set<String> items = new HashSet<>();
    items.add("a");
    items.add("b");
    items.add("c");
    e.search(q);
    // OK, the problem here is we have no way of knowing whether nalle or
    // juhu was added first, since we have passed through HashMap instances
    // inside the implementation
    AndItem root = (AndItem) q.getModel().getQueryTree().getRoot();
    Iterator<?> iterator = root.getItemIterator();
    while (iterator.hasNext()) {
        WordItem word = (WordItem) iterator.next();
        if (items.contains(word.stringValue())) {
            items.remove(word.stringValue());
        } else {
            assertFalse("Got unexpected item in query tree: " + word.stringValue(), true);
        }
    }
    assertEquals("Not all expected items found in query.", 0, items.size());
    Set<StringPair> nastierItems = new HashSet<>();
    nastierItems.add(new StringPair("", "a"));
    nastierItems.add(new StringPair("juhu.22[gnuff]", "b"));
    nastierItems.add(new StringPair("gnuff[8].name(\"tralala\")", "c"));
    q = new Query("?query=a&query.juhu=b&defidx.juhu=juhu.22[gnuff]&query.nalle=c&defidx.nalle=gnuff[8].name(%22tralala%22)");
    e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts()));
    e.search(q);
    root = (AndItem) q.getModel().getQueryTree().getRoot();
    iterator = root.getItemIterator();
    while (iterator.hasNext()) {
        WordItem word = (WordItem) iterator.next();
        StringPair asPair = new StringPair(word.getIndexName(), word.stringValue());
        if (nastierItems.contains(asPair)) {
            nastierItems.remove(asPair);
        } else {
            assertFalse("Got unexpected item in query tree: (" + word.getIndexName() + ", " + word.stringValue() + ")", true);
        }
    }
    assertEquals("Not all expected items found in query.", 0, nastierItems.size());
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) IndexFacts(com.yahoo.prelude.IndexFacts) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) HashSet(java.util.HashSet)

Example 52 with IndexFacts

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

the class SortingDegraderTestCase method createIndexFacts.

private IndexFacts createIndexFacts() {
    IndexFacts indexFacts = new IndexFacts();
    Index fastSearchAttribute1 = new Index("a1");
    fastSearchAttribute1.setFastSearch(true);
    fastSearchAttribute1.setNumerical(true);
    Index fastSearchAttribute2 = new Index("a2");
    fastSearchAttribute2.setFastSearch(true);
    fastSearchAttribute2.setNumerical(true);
    Index nonFastSearchAttribute = new Index("nonFastSearchAttribute");
    nonFastSearchAttribute.setNumerical(true);
    Index stringAttribute = new Index("stringAttribute");
    stringAttribute.setFastSearch(true);
    indexFacts.addIndex("test", fastSearchAttribute1);
    indexFacts.addIndex("test", fastSearchAttribute2);
    indexFacts.addIndex("test", nonFastSearchAttribute);
    indexFacts.addIndex("stringAttribute", stringAttribute);
    return indexFacts;
}
Also used : IndexFacts(com.yahoo.prelude.IndexFacts) Index(com.yahoo.prelude.Index)

Example 53 with IndexFacts

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

the class RangeQueryOptimizerTestCase method parseQuery.

private Item parseQuery(String query) {
    IndexFacts indexFacts = new IndexFacts();
    Parser parser = ParserFactory.newInstance(Query.Type.ADVANCED, new ParserEnvironment().setIndexFacts(indexFacts).setLinguistics(linguistics));
    return parser.parse(new Parsable().setQuery(query)).getRoot();
}
Also used : IndexFacts(com.yahoo.prelude.IndexFacts) Parsable(com.yahoo.search.query.parser.Parsable) ParserEnvironment(com.yahoo.search.query.parser.ParserEnvironment) Parser(com.yahoo.search.query.parser.Parser)

Example 54 with IndexFacts

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

the class RangeQueryOptimizerTestCase method createIndexFacts.

private static IndexFacts createIndexFacts() {
    IndexFacts indexFacts = new IndexFacts();
    Index singleValue1 = new Index("s");
    Index singleValue2 = new Index("t");
    Index multiValue = new Index("m");
    multiValue.setMultivalue(true);
    indexFacts.addIndex("test", singleValue1);
    indexFacts.addIndex("test", singleValue2);
    indexFacts.addIndex("test", multiValue);
    return indexFacts;
}
Also used : IndexFacts(com.yahoo.prelude.IndexFacts) Index(com.yahoo.prelude.Index)

Example 55 with IndexFacts

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

the class ExecutionTestCase method testContextCacheMoreSearchers.

public void testContextCacheMoreSearchers() {
    IndexFacts[] contextsBefore = new IndexFacts[7];
    IndexFacts[] contextsAfter = new IndexFacts[7];
    List<Searcher> l = new ArrayList<>(7);
    l.add(new ContextCacheSearcher(0, contextsBefore, contextsAfter));
    l.add(new ContextCacheSearcher(1, contextsBefore, contextsAfter));
    l.add(new ContextCacheSearcher(2, contextsBefore, contextsAfter));
    l.add(new ContextCacheSearcher(3, contextsBefore, contextsAfter));
    l.add(new ContextCacheSearcher(4, contextsBefore, contextsAfter));
    l.add(new ContextCacheSearcher(5, contextsBefore, contextsAfter));
    l.add(new ContextCacheSearcher(6, contextsBefore, contextsAfter));
    Chain<Searcher> chain = new Chain<>(l);
    Query query = new Query("?mutatecontext=2,4");
    new Execution(chain, Execution.Context.createContextStub()).search(query);
    assertSame(contextsBefore[0], contextsAfter[0]);
    assertSame(contextsBefore[1], contextsAfter[1]);
    assertSame(contextsBefore[2], contextsAfter[2]);
    assertSame(contextsBefore[3], contextsAfter[3]);
    assertSame(contextsBefore[4], contextsAfter[4]);
    assertSame(contextsBefore[5], contextsAfter[5]);
    assertSame(contextsBefore[6], contextsAfter[6]);
    assertSame(contextsBefore[0], contextsBefore[1]);
    assertNotSame(contextsBefore[1], contextsBefore[2]);
    assertSame(contextsBefore[2], contextsBefore[3]);
    assertNotSame(contextsBefore[3], contextsBefore[4]);
    assertSame(contextsBefore[4], contextsBefore[5]);
    assertSame(contextsBefore[5], contextsBefore[6]);
}
Also used : Chain(com.yahoo.component.chain.Chain) Execution(com.yahoo.search.searchchain.Execution) IndexFacts(com.yahoo.prelude.IndexFacts) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) ArrayList(java.util.ArrayList)

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