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;
}
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);
}
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);
}
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);
}
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));
}
Aggregations