use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class LiteralBoostSearcher method addLiterals.
private void addLiterals(RankItem rankTerms, Item item, IndexFacts.Session indexFacts) {
if (item == null)
return;
if (item instanceof NotItem) {
addLiterals(rankTerms, ((NotItem) item).getPositiveItem(), indexFacts);
} else if (item instanceof CompositeItem) {
for (Iterator<Item> i = ((CompositeItem) item).getItemIterator(); i.hasNext(); ) addLiterals(rankTerms, i.next(), indexFacts);
} else if (item instanceof TermItem) {
TermItem termItem = (TermItem) item;
Index index = indexFacts.getIndex(termItem.getIndexName());
if (index.getLiteralBoost())
rankTerms.addItem(new WordItem(toLowerCase(termItem.getRawWord()), index.getName() + "_literal"));
}
}
use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class CJKSearcher method hasOverlappingTokens.
/*
* We have overlapping tokens (see
* com.yahoo.prelude.querytransform.test.CJKSearcherTestCase
* .testCjkQueryWithOverlappingTokens and ParseTestCase for an explanation)
* if the sum of length of tokens is greater than the lenght of the original
* word
*/
private boolean hasOverlappingTokens(PhraseSegmentItem segments) {
int segmentsLength = 0;
for (Iterator<Item> i = segments.getItemIterator(); i.hasNext(); ) {
WordItem segment = (WordItem) i.next();
segmentsLength += segment.getWord().length();
}
return segmentsLength > segments.getRawWord().length();
}
use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class FastSearcherTestCase method testSinglePhaseCachedSupersets.
@Ignore
public void testSinglePhaseCachedSupersets() {
Logger.getLogger(FastSearcher.class.getName()).setLevel(Level.ALL);
MockFSChannel.resetDocstamp();
FastSearcher fastSearcher = new FastSearcher(new MockBackend(), new FS4ResourcePool(1), new MockDispatcher(Collections.emptyList()), new SummaryParameters(null), new ClusterParams("testhittype"), new CacheParams(100, 1e64), documentdbInfoConfig);
CacheControl c = fastSearcher.getCacheControl();
Result result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 2);
Query q = new Query("?query=ignored");
((WordItem) q.getModel().getQueryTree().getRoot()).setUniqueID(1);
QueryPacket queryPacket = QueryPacket.create(q);
CacheKey k = new CacheKey(queryPacket);
PacketWrapper p = c.lookup(k, q);
assertEquals(1, p.getResultPackets().size());
result = doSearch(fastSearcher, new Query("?query=ignored"), 1, 1);
p = c.lookup(k, q);
// ensure we don't get redundant QueryResultPacket instances
// in the cache
assertEquals(1, p.getResultPackets().size());
assertEquals(1, result.getConcreteHitCount());
for (int i = 0; i < result.getHitCount(); i++) {
assertTrue(result.hits().get(i).isCached());
}
result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 1);
p = c.lookup(k, q);
assertEquals(1, p.getResultPackets().size());
assertEquals(1, result.getConcreteHitCount());
for (int i = 0; i < result.getHitCount(); i++) {
assertTrue(result.hits().get(i).isCached());
}
}
use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class GetRawWordTestCase method testGetRawWord.
@Test
public void testGetRawWord() {
Query query = new Query("?query=%C4%B0%C5%9EBANKASI%20GAZ%C4%B0EM%C4%B0R&searchChain=vespa");
assertEquals("AND \u0130\u015EBANKASI GAZ\u0130EM\u0130R", query.getModel().getQueryTree().toString());
AndItem root = (AndItem) query.getModel().getQueryTree().getRoot();
{
WordItem word = (WordItem) root.getItem(0);
assertEquals("\u0130\u015EBANKASI", word.getRawWord());
assertEquals(0, word.getOrigin().start);
assertEquals(9, word.getOrigin().end);
}
{
WordItem word = (WordItem) root.getItem(1);
assertEquals("GAZ\u0130EM\u0130R", word.getRawWord());
assertEquals(10, word.getOrigin().start);
assertEquals(18, word.getOrigin().end);
}
assertEquals("Total string is just these words", 18, ((WordItem) root.getItem(0)).getOrigin().getSuperstring().length());
}
use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class ParseTestCase method testIndexSuffixExtraSpace.
@Test
public void testIndexSuffixExtraSpace() {
Item root = tester.assertParsed("OR foo suffix", "foo:* suffix", Query.Type.ANY);
assertTrue(((OrItem) root).getItem(0) instanceof WordItem);
assertTrue(((OrItem) root).getItem(1) instanceof WordItem);
}
Aggregations