Search in sources :

Example 16 with IndexFacts

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

the class RewriterFeatures method convertStringToQTree.

/**
 * Convert String to query tree
 *
 * @param stringToParse The string to be converted to a
 *                      query tree
 * @param query Query object from searcher
 * @return Item The resulting query tree
 */
static Item convertStringToQTree(Query query, String stringToParse) {
    RewriterUtils.log(logger, query, "Converting string [" + stringToParse + "] to query tree");
    if (stringToParse == null) {
        return new NullItem();
    }
    Model model = query.getModel();
    CustomParser parser = (CustomParser) ParserFactory.newInstance(model.getType(), ParserEnvironment.fromExecutionContext(query.getModel().getExecution().context()));
    IndexFacts indexFacts = new IndexFacts();
    Item item = parser.parse(stringToParse, null, model.getParsingLanguage(), indexFacts.newSession(model.getSources(), model.getRestrict()), model.getDefaultIndex());
    RewriterUtils.log(logger, query, "Converted string: [" + item.toString() + "]");
    return item;
}
Also used : IndexFacts(com.yahoo.prelude.IndexFacts) CustomParser(com.yahoo.prelude.query.parser.CustomParser)

Example 17 with IndexFacts

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

the class ParseTestCase method testExactMatchParsing1.

@Test
public void testExactMatchParsing1() {
    IndexFacts indexFacts = ParsingTester.createIndexFacts();
    Index index1 = new Index("testexact1");
    index1.setExact(true, null);
    Index index2 = new Index("testexact2");
    index2.setExact(true, "()/aa*::*&");
    indexFacts.addIndex("testsd", index1);
    indexFacts.addIndex("testsd", index2);
    ParsingTester customTester = new ParsingTester(indexFacts);
    customTester.assertParsed("testexact1:/,%&#", "testexact1:/,%&#", Query.Type.ALL);
    customTester.assertParsed("testexact2:/,%&#!!", "testexact2:/,%&#!!()/aa*::*&", Query.Type.ALL);
    customTester.assertParsed("AND word1 (OR testexact1:word2 testexact1:word3)", "word1 AND (testexact1:word2 OR testexact1:word3 )", Query.Type.ADVANCED);
    customTester.assertParsed("AND word (OR testexact1:AND testexact1:OR)", "word AND (testexact1: AND OR testexact1: OR )", Query.Type.ADVANCED);
}
Also used : IndexFacts(com.yahoo.prelude.IndexFacts) Index(com.yahoo.prelude.Index) Test(org.junit.Test)

Example 18 with IndexFacts

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

the class ParseTestCase method testExactMatchParsing2.

/**
 * Testing terminators containing control characters in conjunction with those control characters
 */
@Test
public void testExactMatchParsing2() {
    IndexFacts indexFacts = ParsingTester.createIndexFacts();
    Index index1 = new Index("testexact1");
    index1.setExact(true, "*!*");
    indexFacts.addIndex("testsd", index1);
    ParsingTester customTester = new ParsingTester(indexFacts);
    customTester.assertParsed("testexact1:_-_*!200", "testexact1:_-_*!**!!", Query.Type.ALL);
}
Also used : IndexFacts(com.yahoo.prelude.IndexFacts) Index(com.yahoo.prelude.Index) Test(org.junit.Test)

Example 19 with IndexFacts

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

the class ParseTestCase method testExactMatchParsing3.

/**
 * Testing terminators containing control characters in conjunction with those control characters
 */
@Test
public void testExactMatchParsing3() {
    IndexFacts indexFacts = ParsingTester.createIndexFacts();
    Index index1 = new Index("testexact1");
    index1.setExact(true, "*");
    indexFacts.addIndex("testsd", index1);
    ParsingTester customTester = new ParsingTester(indexFacts);
    customTester.assertParsed("testexact1:_-_*!200", "testexact1:_-_**!!", Query.Type.ALL);
}
Also used : IndexFacts(com.yahoo.prelude.IndexFacts) Index(com.yahoo.prelude.Index) Test(org.junit.Test)

Example 20 with IndexFacts

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

the class ClusterSearcherTestCase 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"));
    clusters.put("type1", Arrays.asList("type6"));
    Map<String, SearchDefinition> searchDefs = new LinkedHashMap<>();
    searchDefs.put("type1", new SearchDefinition("type1"));
    searchDefs.put("type2", new SearchDefinition("type2"));
    searchDefs.put("type3", new SearchDefinition("type3"));
    searchDefs.put("type4", new SearchDefinition("type4"));
    searchDefs.put("type5", new SearchDefinition("type5"));
    searchDefs.put("type6", new SearchDefinition("type6"));
    SearchDefinition union = new SearchDefinition("union");
    return new IndexFacts(new IndexModel(clusters, searchDefs, union));
}
Also used : IndexFacts(com.yahoo.prelude.IndexFacts) ArrayList(java.util.ArrayList) 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