Search in sources :

Example 86 with Query

use of com.yahoo.search.Query in project vespa by vespa-engine.

the class PosSearcherTestCase method testInvalidInput.

/**
 * Tests input parameters that should report errors.
 */
@Test
public void testInvalidInput() {
    PosSearcher searcher = new PosSearcher();
    Result result;
    Query q = new Query();
    q.properties().set("pos.ll", "NE74.14;E14.48");
    result = doSearch(searcher, q, 0, 10);
    assertEquals("Error in pos parameters: Unable to parse lat/long string 'NE74.14;E14.48': already set direction once, cannot add direction: E", ((ErrorHit) result.hits().get(0)).errors().iterator().next().getDetailedMessage());
    q = new Query();
    q.properties().set("pos.ll", "NE74.14;E14.48");
    q.properties().set("pos.xy", "82400, 72800");
    result = doSearch(searcher, q, 0, 10);
    assertEquals("Error in pos parameters: Cannot handle both lat/long and xy coords at the same time", ((ErrorHit) result.hits().get(0)).errors().iterator().next().getDetailedMessage());
}
Also used : Query(com.yahoo.search.Query) PosSearcher(com.yahoo.prelude.searcher.PosSearcher) ErrorHit(com.yahoo.search.result.ErrorHit) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 87 with Query

use of com.yahoo.search.Query in project vespa by vespa-engine.

the class PosSearcherTestCase method testBasics.

/**
 * Tests basic lat/long input.
 */
@Test
public void testBasics() {
    Query q = new Query();
    q.properties().set("pos.ll", "N0;E0");
    doSearch(searcher, q, 0, 10);
    assertEquals("(2,0,0,450668,0,1,0,4294967295)", q.getRanking().getLocation().toString());
    q = new Query();
    q.properties().set("pos.ll", "N60;E30");
    doSearch(searcher, q, 0, 10);
    assertEquals("(2,30000000,60000000,450668,0,1,0,2147483647)", q.getRanking().getLocation().toString());
}
Also used : Query(com.yahoo.search.Query) Test(org.junit.Test)

Example 88 with Query

use of com.yahoo.search.Query in project vespa by vespa-engine.

the class PosSearcherTestCase method testBoundingBox.

/**
 * Tests basic bounding box input.
 */
@Test
public void testBoundingBox() {
    Query q = new Query();
    q.properties().set("pos.bb", "n=51.9,s=50.2,e=0.34,w=-10.01");
    doSearch(searcher, q, 0, 10);
    assertEquals("[2,-10010000,50200000,340000,51900000]", q.getRanking().getLocation().toString());
    q = new Query();
    q.properties().set("pos.bb", "n=0,s=0,e=123.456789,w=-123.456789");
    doSearch(searcher, q, 0, 10);
    assertEquals("[2,-123456789,0,123456789,0]", q.getRanking().getLocation().toString());
    q = new Query();
    q.properties().set("pos.bb", "n=12.345678,s=-12.345678,e=0,w=0");
    doSearch(searcher, q, 0, 10);
    assertEquals("[2,0,-12345678,0,12345678]", q.getRanking().getLocation().toString());
    q = new Query();
    q.properties().set("pos.bb", "n=0.000001,s=-0.000001,e=0.000001,w=-0.000001");
    doSearch(searcher, q, 0, 10);
    assertEquals("[2,-1,-1,1,1]", q.getRanking().getLocation().toString());
}
Also used : Query(com.yahoo.search.Query) Test(org.junit.Test)

Example 89 with Query

use of com.yahoo.search.Query in project vespa by vespa-engine.

the class QueryValidatingSearcherTestCase method testBasic.

public void testBasic() {
    // Setup
    Map<Searcher, Searcher> chained = new HashMap<>();
    Query query = new Query("?query=test");
    Result result = new Result(query);
    result.hits().add(new Hit("ymail://1111111111/AQAAAP7JgwEAj6XjQQAAAO/+ggA=", 950));
    Searcher validator = new QueryValidatingSearcher();
    DocumentSourceSearcher source = new DocumentSourceSearcher();
    chained.put(validator, source);
    source.addResult(query, result);
    // Exercise
    Result returnedResult = doSearch(validator, query, 0, 10, chained);
    // Validate
    assertEquals(1, returnedResult.getHitCount());
    assertNull(returnedResult.hits().getError());
    returnedResult = doSearch(validator, query, 0, 1001, chained);
    assertEquals(0, returnedResult.getConcreteHitCount());
    assertEquals(4, returnedResult.hits().getError().getCode());
    returnedResult = doSearch(validator, query, 1001, 10, chained);
    assertEquals(0, returnedResult.getConcreteHitCount());
    assertEquals(4, returnedResult.hits().getError().getCode());
}
Also used : Hit(com.yahoo.search.result.Hit) Query(com.yahoo.search.Query) HashMap(java.util.HashMap) Searcher(com.yahoo.search.Searcher) QueryValidatingSearcher(com.yahoo.prelude.searcher.QueryValidatingSearcher) DocumentSourceSearcher(com.yahoo.search.searchchain.testutil.DocumentSourceSearcher) QueryValidatingSearcher(com.yahoo.prelude.searcher.QueryValidatingSearcher) DocumentSourceSearcher(com.yahoo.search.searchchain.testutil.DocumentSourceSearcher) Result(com.yahoo.search.Result)

Example 90 with Query

use of com.yahoo.search.Query in project vespa by vespa-engine.

the class AutomataTestCase method testAutomataRuleBase.

public void testAutomataRuleBase() throws Exception {
    RuleBase ruleBase = searcher.getDefaultRuleBase();
    assertEquals(RuleBase.class, ruleBase.getClass());
    assertTrue(ruleBase.getSource().endsWith(root + "automatarules.sr"));
    assertEquals(root + "semantics.fsa", ruleBase.getAutomataFile());
    Query query = new Query("?query=sony+digital+camera");
    ruleBase.analyze(query, 0);
    assertEquals("RANK (AND sony digital camera) dsp1:sony dsp5:digicamera", query.getModel().getQueryTree().getRoot().toString());
    query = new Query("?query=sony+digital+camera&rules.reload");
    ruleBase = searcher.getDefaultRuleBase();
    assertTrue(ruleBase.getSource().endsWith(root + "automatarules.sr"));
    assertEquals(root + "semantics.fsa", ruleBase.getAutomataFile());
    ruleBase.analyze(query, 0);
    assertEquals("RANK (AND sony digital camera) dsp1:sony dsp5:digicamera", query.getModel().getQueryTree().getRoot().toString());
}
Also used : Query(com.yahoo.search.Query) RuleBase(com.yahoo.prelude.semantics.RuleBase)

Aggregations

Query (com.yahoo.search.Query)689 Test (org.junit.Test)415 Result (com.yahoo.search.Result)229 Execution (com.yahoo.search.searchchain.Execution)184 Searcher (com.yahoo.search.Searcher)82 QueryProfile (com.yahoo.search.query.profile.QueryProfile)63 Hit (com.yahoo.search.result.Hit)52 Chain (com.yahoo.component.chain.Chain)47 IndexFacts (com.yahoo.prelude.IndexFacts)44 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)37 AndItem (com.yahoo.prelude.query.AndItem)33 WordItem (com.yahoo.prelude.query.WordItem)33 FastHit (com.yahoo.prelude.fastsearch.FastHit)31 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)27 HitGroup (com.yahoo.search.result.HitGroup)24 Item (com.yahoo.prelude.query.Item)21 HashMap (java.util.HashMap)20 CacheKey (com.yahoo.prelude.fastsearch.CacheKey)18 GroupingRequest (com.yahoo.search.grouping.GroupingRequest)18 ArrayList (java.util.ArrayList)18