Search in sources :

Example 1 with NotItem

use of com.yahoo.prelude.query.NotItem 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"));
    }
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) NotItem(com.yahoo.prelude.query.NotItem) Iterator(java.util.Iterator) Index(com.yahoo.prelude.Index) WordItem(com.yahoo.prelude.query.WordItem) TermItem(com.yahoo.prelude.query.TermItem)

Example 2 with NotItem

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

the class QueryLanguageTestCase method testNotItem.

@Test
public void testNotItem() {
    NotItem n = new NotItem();
    n.addNegativeItem(new WordItem("notthis"));
    n.addNegativeItem(new WordItem("andnotthis"));
    n.addPositiveItem(new WordItem("butthis"));
    assertEquals("+butthis -notthis -andnotthis", n.toString());
}
Also used : NotItem(com.yahoo.prelude.query.NotItem) WordItem(com.yahoo.prelude.query.WordItem) Test(org.junit.Test)

Example 3 with NotItem

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

the class QueryRewriteTestCase method assertAndNotMovedUp.

@Test
public void assertAndNotMovedUp() {
    Query query = new Query();
    NotItem not = new NotItem();
    not.addPositiveItem(new WordItem("a"));
    not.addNegativeItem(new WordItem("na"));
    AndItem and = new AndItem();
    and.addItem(not);
    query.getModel().getQueryTree().setRoot(and);
    QueryRewrite.optimizeAndNot(query);
    assertTrue(query.getModel().getQueryTree().getRoot() instanceof NotItem);
    NotItem n = (NotItem) query.getModel().getQueryTree().getRoot();
    assertEquals(2, n.getItemCount());
    assertTrue(n.getPositiveItem() instanceof AndItem);
    AndItem a = (AndItem) n.getPositiveItem();
    assertEquals(1, a.getItemCount());
    assertEquals("a", a.getItem(0).toString());
    assertEquals("na", n.getItem(1).toString());
}
Also used : NotItem(com.yahoo.prelude.query.NotItem) Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) Test(org.junit.Test)

Example 4 with NotItem

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

the class QueryRewriteTestCase method assertMultipleAndNotIsCollapsed.

@Test
public void assertMultipleAndNotIsCollapsed() {
    Query query = new Query();
    NotItem not1 = new NotItem();
    not1.addPositiveItem(new WordItem("a"));
    not1.addNegativeItem(new WordItem("na1"));
    not1.addNegativeItem(new WordItem("na2"));
    NotItem not2 = new NotItem();
    not2.addPositiveItem(new WordItem("b"));
    not2.addNegativeItem(new WordItem("nb"));
    AndItem and = new AndItem();
    and.addItem(new WordItem("1"));
    and.addItem(not1);
    and.addItem(new WordItem("2"));
    and.addItem(not2);
    and.addItem(new WordItem("3"));
    query.getModel().getQueryTree().setRoot(and);
    QueryRewrite.optimizeAndNot(query);
    assertTrue(query.getModel().getQueryTree().getRoot() instanceof NotItem);
    NotItem n = (NotItem) query.getModel().getQueryTree().getRoot();
    assertTrue(n.getPositiveItem() instanceof AndItem);
    assertEquals(4, n.getItemCount());
    AndItem a = (AndItem) n.getPositiveItem();
    assertEquals(5, a.getItemCount());
    assertEquals("na1", n.getItem(1).toString());
    assertEquals("na2", n.getItem(2).toString());
    assertEquals("nb", n.getItem(3).toString());
    assertEquals("1", a.getItem(0).toString());
    assertEquals("a", a.getItem(1).toString());
    assertEquals("2", a.getItem(2).toString());
    assertEquals("b", a.getItem(3).toString());
    assertEquals("3", a.getItem(4).toString());
}
Also used : NotItem(com.yahoo.prelude.query.NotItem) Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) Test(org.junit.Test)

Example 5 with NotItem

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

the class GroupingExecutorTestCase method testIllegalQuery.

@Test
public void testIllegalQuery() {
    Execution exc = newExecution(new GroupingExecutor());
    Query query = new Query();
    NotItem notItem = new NotItem();
    notItem.addNegativeItem(new WordItem("negative"));
    query.getModel().getQueryTree().setRoot(notItem);
    Result result = exc.search(query);
    com.yahoo.search.result.ErrorMessage message = result.hits().getError();
    assertNotNull("Got error", message);
    assertEquals("Illegal query", message.getMessage());
    assertEquals("Can not search for only negative items", message.getDetailedMessage());
    assertEquals(3, message.getCode());
}
Also used : Execution(com.yahoo.search.searchchain.Execution) NotItem(com.yahoo.prelude.query.NotItem) Query(com.yahoo.search.Query) WordItem(com.yahoo.prelude.query.WordItem) ErrorMessage(com.yahoo.search.result.ErrorMessage) Result(com.yahoo.search.Result) HitsAggregationResult(com.yahoo.searchlib.aggregation.HitsAggregationResult) CountAggregationResult(com.yahoo.searchlib.aggregation.CountAggregationResult) MinAggregationResult(com.yahoo.searchlib.aggregation.MinAggregationResult) MaxAggregationResult(com.yahoo.searchlib.aggregation.MaxAggregationResult) Test(org.junit.Test)

Aggregations

NotItem (com.yahoo.prelude.query.NotItem)11 WordItem (com.yahoo.prelude.query.WordItem)9 Test (org.junit.Test)8 AndItem (com.yahoo.prelude.query.AndItem)6 CompositeItem (com.yahoo.prelude.query.CompositeItem)4 Item (com.yahoo.prelude.query.Item)3 OrItem (com.yahoo.prelude.query.OrItem)3 RankItem (com.yahoo.prelude.query.RankItem)3 SubstringItem (com.yahoo.prelude.query.SubstringItem)3 Query (com.yahoo.search.Query)3 IntItem (com.yahoo.prelude.query.IntItem)2 PhraseItem (com.yahoo.prelude.query.PhraseItem)2 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)2 PrefixItem (com.yahoo.prelude.query.PrefixItem)2 SuffixItem (com.yahoo.prelude.query.SuffixItem)2 Index (com.yahoo.prelude.Index)1 EquivItem (com.yahoo.prelude.query.EquivItem)1 MarkerWordItem (com.yahoo.prelude.query.MarkerWordItem)1 NearItem (com.yahoo.prelude.query.NearItem)1 NullItem (com.yahoo.prelude.query.NullItem)1