use of com.yahoo.search.Searcher in project vespa by vespa-engine.
the class FieldCollapsingSearcherTestCase method testCollapsingDispersedCollection.
/**
* Tests collapsing of "messy" data
*/
@Test
public void testCollapsingDispersedCollection() {
// Set up
Map<Searcher, Searcher> chained = new HashMap<>();
FieldCollapsingSearcher collapse = new FieldCollapsingSearcher(1, 2.0, "amid");
DocumentSourceSearcher docsource = new DocumentSourceSearcher();
chained.put(collapse, docsource);
Query q = new Query("?query=test_collapse&collapse=true&collapsefield=amid");
// The searcher turns off collapsing further on in the chain
q.properties().set("collapse", "0");
Result r = new Result(q);
r.hits().add(createHit("http://acme.org/a.html", 10, 1));
r.hits().add(createHit("http://acme.org/b.html", 10, 1));
r.hits().add(createHit("http://acme.org/c.html", 10, 0));
r.hits().add(createHit("http://acme.org/d.html", 10, 0));
r.hits().add(createHit("http://acme.org/e.html", 10, 0));
r.hits().add(createHit("http://acme.org/f.html", 10, 0));
r.hits().add(createHit("http://acme.org/g.html", 10, 0));
r.hits().add(createHit("http://acme.org/h.html", 10, 0));
r.hits().add(createHit("http://acme.org/i.html", 10, 0));
r.hits().add(createHit("http://acme.org/j.html", 10, 1));
r.setTotalHitCount(10);
docsource.addResult(q, r);
// Test collapsing
q = new Query("?query=test_collapse&collapse=true&collapsefield=amid");
r = doSearch(collapse, q, 0, 3, chained);
assertEquals(2, r.getHitCount());
assertHit("http://acme.org/a.html", 10, 1, r.hits().get(0));
assertHit("http://acme.org/c.html", 10, 0, r.hits().get(1));
}
use of com.yahoo.search.Searcher in project vespa by vespa-engine.
the class FieldCollapsingSearcherTestCase method testFieldCollapsingWithoutHits.
@Test
public void testFieldCollapsingWithoutHits() {
// Set up
Map<Searcher, Searcher> chained = new HashMap<>();
FieldCollapsingSearcher collapse = new FieldCollapsingSearcher("other");
ZeroHitsControl checker = new ZeroHitsControl();
chained.put(collapse, checker);
Query q = new Query("?query=test_collapse&collapsefield=amid");
Result r = doSearch(collapse, q, 0, 0, chained);
assertEquals(0, r.getHitCount());
assertNull(r.hits().getError());
assertEquals(1, checker.queryCount);
}
use of com.yahoo.search.Searcher in project vespa by vespa-engine.
the class FieldCollapsingSearcherTestCase method testCollapsingLargeCollection.
/**
* Tests that collapsing many hits from one site works, and without
* an excessive number of backend requests
*/
@Test
public void testCollapsingLargeCollection() {
// Set up
Map<Searcher, Searcher> chained = new HashMap<>();
FieldCollapsingSearcher collapse = new FieldCollapsingSearcher(4, 2.0, "amid");
DocumentSourceSearcher docsource = new DocumentSourceSearcher();
chained.put(collapse, docsource);
Query q = new Query("?query=test_collapse&collapsesize=1&collapsefield=amid");
// The searcher turns off collapsing further on in the chain
q.properties().set("collapse", "0");
Result r = new Result(q);
r.hits().add(createHit("http://acme.org/a.html", 10, 0));
r.hits().add(createHit("http://acme.org/b.html", 9, 0));
r.hits().add(createHit("http://acme.org/c.html", 9, 0));
r.hits().add(createHit("http://acme.org/d.html", 8, 0));
r.hits().add(createHit("http://acme.org/e.html", 8, 0));
r.hits().add(createHit("http://acme.org/f.html", 7, 0));
r.hits().add(createHit("http://acme.org/g.html", 7, 0));
r.hits().add(createHit("http://acme.org/h.html", 6, 0));
r.hits().add(createHit("http://acme.org/i.html", 5, 1));
r.hits().add(createHit("http://acme.org/j.html", 4, 2));
r.setTotalHitCount(10);
docsource.addResult(q, r);
// Test collapsing
q = new Query("?query=test_collapse&collapsesize=1&collapsefield=amid");
r = doSearch(collapse, q, 0, 2, chained);
assertEquals(2, r.getHitCount());
assertEquals(2, docsource.getQueryCount());
assertHit("http://acme.org/a.html", 10, 0, r.hits().get(0));
assertHit("http://acme.org/i.html", 5, 1, r.hits().get(1));
// Next results
docsource.resetQueryCount();
r = doSearch(collapse, q, 2, 2, chained);
assertEquals(1, r.getHitCount());
assertEquals(2, docsource.getQueryCount());
assertHit("http://acme.org/j.html", 4, 2, r.hits().get(0));
}
use of com.yahoo.search.Searcher in project vespa by vespa-engine.
the class JuniperSearcherTestCase method testExplicitTwoPhase.
@Test
public void testExplicitTwoPhase() {
Chain<Searcher> searchChain = createSearchChain("one", "\u001e\uFFFAbe\uFFFB within the set of \u001f\uFFF9documents\uFFFAdocument\uFFFB\u001f. \uFFF9phrases\uFFFA\u001E\uFFFA\uFFFB to as a remedy). Each of the \u001fdocument\u001f \uFFF9fields\uFFFAfield\uFFFB in a catalog can be \uFFF9\u001e");
Query q = new Query("?query=12");
Result check = createExecution(searchChain).search(q);
assertEquals(1, check.getHitCount());
assertNull(check.hits().get(0).getField("dynteaser"));
createExecution(searchChain).fill(check);
assertEquals(1, check.getHitCount());
assertEquals("<sep /> within the set of <hi>documents</hi>. phrases<sep /> to as a remedy). Each of the <hi>document</hi> fields in a catalog can be <sep />", check.hits().get(0).getField("dynteaser").toString());
}
use of com.yahoo.search.Searcher in project vespa by vespa-engine.
the class ClusterSearcherTestCase method testSimple.
public void testSimple() {
Hit blockingHit = new Hit("blocking");
Hit nonblockingHit = new Hit("nonblocking");
BlockingBackendSearcher blockingSearcher = new BlockingBackendSearcher(blockingHit);
List<Searcher> searchers = new ArrayList<>();
searchers.add(blockingSearcher);
searchers.add(new TestingBackendSearcher(nonblockingHit));
ClusterSearcher<?> provider = new SearcherClusterSearcher(new ComponentId("simple"), searchers, new SimpleHasher<>());
Result blockingResult = new Execution(provider, Execution.Context.createContextStub()).search(new SimpleQuery(0));
assertEquals(blockingHit, blockingResult.hits().get(0));
Result nonblockingResult = new Execution(provider, Execution.Context.createContextStub()).search(new SimpleQuery(1));
assertEquals(nonblockingHit, nonblockingResult.hits().get(0));
blockingSearcher.setBlocking(true);
blockingResult = new Execution(provider, Execution.Context.createContextStub()).search(new SimpleQuery(0));
assertEquals(blockingResult.hits().get(0), nonblockingHit);
nonblockingResult = new Execution(provider, Execution.Context.createContextStub()).search(new SimpleQuery(1));
assertEquals(nonblockingResult.hits().get(0), nonblockingHit);
}
Aggregations