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