use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class TestLindenServerWithFacet method earlyTermination.
@Test
public void earlyTermination() throws Exception {
String bql = "select * from linden browse by PublishDate, Author, Author(2), PublishDate(10, '2010'), " + "PublishDate(10, '2010/10'), PublishDate(10, '2010/10/15'), PublishDate(10, '2010/13') in top 5";
LindenResult result = clusterClient.search(bql);
Assert.assertEquals(10, result.getTotalHits());
Assert.assertEquals(7, result.getFacetResultsSize());
Assert.assertEquals("LindenFacetResult(dim:PublishDate, value:10, childCount:3, " + "labelValues:[LindenLabelAndValue(label:2010, value:4), LindenLabelAndValue(label:2012, value:4), " + "LindenLabelAndValue(label:1999, value:2)])", result.getFacetResults().get(0).toString());
Assert.assertEquals("LindenFacetResult(dim:Author, value:10, childCount:5, " + "labelValues:[LindenLabelAndValue(label:Lisa, value:4), " + "LindenLabelAndValue(label:Bob, value:2), " + "LindenLabelAndValue(label:Susan, value:2), " + "LindenLabelAndValue(label:Frank, value:1), " + "LindenLabelAndValue(label:Sue, value:1)])", result.getFacetResults().get(1).toString());
Assert.assertEquals("LindenFacetResult(dim:Author, value:10, childCount:4, " + "labelValues:[LindenLabelAndValue(label:Lisa, value:4), " + "LindenLabelAndValue(label:Bob, value:1)])", result.getFacetResults().get(2).toString());
Assert.assertEquals("LindenFacetResult(dim:PublishDate, path:2010, value:4, childCount:2, " + "labelValues:[LindenLabelAndValue(label:10, value:3), " + "LindenLabelAndValue(label:11, value:1)])", result.getFacetResults().get(3).toString());
Assert.assertEquals("LindenFacetResult(dim:PublishDate, path:2010/10, value:3, childCount:3, " + "labelValues:[LindenLabelAndValue(label:15, value:1), " + "LindenLabelAndValue(label:20, value:1), " + "LindenLabelAndValue(label:25, value:1)])", result.getFacetResults().get(4).toString());
Assert.assertEquals("LindenFacetResult(dim:PublishDate, path:2010/10/15, value:0, childCount:0)", result.getFacetResults().get(5).toString());
Assert.assertEquals("LindenFacetResult(dim:PublishDate, path:2010/13, value:0, childCount:0)", result.getFacetResults().get(6).toString());
}
use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class TestLindenJiebaAnalyzerIndexMode method testIndexMode.
@Test
public void testIndexMode() throws IOException {
String bql = "select * from linden by query is \"title:刘华清\"";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(2, result.getTotalHits());
// phrase test
bql = "select * from linden by query is 'title:\"刘华清\"'";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(2, result.getTotalHits());
bql = "select * from linden by query is 'title:\"海军上将刘华清\"'";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(0, result.getTotalHits());
// snippet test
bql = "select * from linden by query is 'title:(海军上将刘华清中国龙)' snippet title";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(2, result.getTotalHits());
Assert.assertEquals("<b>海军上将</b><b>刘华清</b>", result.getHits().get(0).getSnippets().get("title").getSnippet());
Assert.assertEquals("<b>海军上将</b><b>刘华清</b>!!! <b>中国</b> 人民 李玉洁 尚铁龙 胡晓光", result.getHits().get(1).getSnippets().get("title").getSnippet());
bql = "select * from linden by query is 'title:(海军中国铁龙)' snippet title";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(2, result.getTotalHits());
Assert.assertEquals("<b>海军</b>上将刘华清!!! <b>中国</b> 人民 李玉洁 尚铁龙 胡晓光", result.getHits().get(0).getSnippets().get("title").getSnippet());
}
use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class ResultMerger method mergeGroupSearch.
private static LindenResult mergeGroupSearch(LindenSearchRequest lindenRequest, List<LindenResult> resultList) {
LindenResult mergedResult = resultList.get(0);
if (!mergedResult.isSetHits()) {
mergedResult.setHits(new ArrayList<LindenHit>());
}
String groupField = lindenRequest.getGroupParam().getGroupField();
int innerLimit = lindenRequest.getGroupParam().getGroupInnerLimit();
// traverse LindenResults from shards
for (int i = 1; i < resultList.size(); ++i) {
LindenResult subResult = resultList.get(i);
if (!subResult.isSetHits()) {
continue;
}
mergedResult.totalHits += subResult.totalHits;
mergedResult.totalGroups = Math.max(mergedResult.totalGroups, subResult.totalGroups);
mergedResult.totalGroupHits += subResult.totalGroupHits;
// traverse groups in waiting LindenResult
for (LindenHit subGroup : subResult.getHits()) {
String groupName = subGroup.getFields().get(groupField);
boolean isFound = false;
// find the group in the merged groupList
for (int j = 0; j < mergedResult.getHitsSize(); ++j) {
LindenHit mergedHit = mergedResult.getHits().get(j);
if (mergedHit.getFields().get(groupField).equals(groupName)) {
Iterable<LindenHit> groupIterable = Iterables.mergeSorted(ImmutableList.of(subGroup.getGroupHits(), mergedHit.getGroupHits()), new LindenHitCmp(null));
List<LindenHit> hits = Lists.newArrayList(Iterables.limit(groupIterable, innerLimit));
if (mergedHit.getScore() < subGroup.getScore()) {
mergedHit = subGroup;
}
mergedHit.setGroupHits(hits);
mergedResult.getHits().set(j, mergedHit);
isFound = true;
break;
}
}
if (!isFound) {
mergedResult.getHits().add(subGroup);
}
}
}
// sort the group by score
Ordering<LindenHit> ordering = new Ordering<LindenHit>() {
@Override
public int compare(@Nullable LindenHit left, @Nullable LindenHit right) {
return Double.compare(left.getScore(), right.getScore());
}
};
List<LindenHit> orderedHits = // offset -> offset+size groups
ordering.greatestOf(mergedResult.getHits(), mergedResult.getHitsSize());
int from = lindenRequest.getOffset();
int size = lindenRequest.getLength();
if (from < orderedHits.size()) {
List<LindenHit> subHits = orderedHits.subList(from, Math.min(from + size, orderedHits.size()));
mergedResult.setHits(subHits);
} else {
mergedResult.setHits(new ArrayList<LindenHit>());
}
return mergedResult;
}
use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class TestLindenWordDelimiterAnalyzer method testIndexMode.
@Test
public void testIndexMode() throws IOException {
String bql = "select * from linden by query is \"title:刘华清\"";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(3, result.getTotalHits());
// phrase test
bql = "select * from linden by query is 'title:\"刘华清\"'";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(2, result.getTotalHits());
bql = "select * from linden by query is 'title:\"海军上将刘华清\"'";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(2, result.getTotalHits());
// snippet test
bql = "select * from linden by query is 'title:(海军上将刘华清中国龙)' snippet title";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(3, result.getTotalHits());
Assert.assertEquals("<b>海</b><b>军</b><b>上</b><b>将</b><b>刘</b><b>华</b><b>清</b>!!! <b>中</b><b>国</b> 人民 李玉洁 尚铁<b>龙</b> 胡晓光", result.getHits().get(0).getSnippets().get("title").getSnippet());
Assert.assertEquals("<b>海</b><b>军</b><b>上</b><b>将</b><b>刘</b><b>华</b><b>清</b>", result.getHits().get(1).getSnippets().get("title").getSnippet());
}
use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class TestGlobalIDF method testGlobalIdf.
@Test
public void testGlobalIdf() throws IOException {
String bql = "select * from linden by flexible_query is 'lucene' global_idf in (title, field1)\n" + "using model test\n" + "begin\n" + " return 1;\n" + "end\n" + "source explain;";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(result.getHits().get(0).getExplanation().getDetails().get(0).getDetails().get(0).getDescription(), result.getHits().get(1).getExplanation().getDetails().get(0).getDetails().get(0).getDescription());
}
Aggregations