本文整理汇总了Java中org.apache.solr.response.ResultContext类的典型用法代码示例。如果您正苦于以下问题:Java ResultContext类的具体用法?Java ResultContext怎么用?Java ResultContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ResultContext类属于org.apache.solr.response包,在下文中一共展示了ResultContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.apache.solr.response.ResultContext; //导入依赖的package包/类
@Override
public void process(ResponseBuilder rb) throws IOException {
SolrParams params = rb.req.getParams();
if (!params.getBool(COMPONENT_NAME, false)) return;
SolrIndexSearcher searcher = rb.req.getSearcher();
IndexSchema schema = searcher.getSchema();
if (schema.getUniqueKeyField() == null) return;
ResultContext rc = (ResultContext) rb.rsp.getValues().get("response");
if (rc.docs.hasScores()) {
processScores(rb, rc.docs, schema, searcher);
} else {
processIds(rb, rc.docs, schema, searcher);
}
}
示例2: testNotLazyField
import org.apache.solr.response.ResultContext; //导入依赖的package包/类
@Test
public void testNotLazyField() throws IOException {
assertU(adoc("id", "7777",
"title", "keyword",
"test_hlt", mkstr(20000)));
assertU(commit());
SolrCore core = h.getCore();
SolrQueryRequest req = req("q", "id:7777", "fl", "id,title,test_hlt");
SolrQueryResponse rsp = new SolrQueryResponse();
core.execute(core.getRequestHandler(req.getParams().get(CommonParams.QT)), req, rsp);
DocList dl = ((ResultContext) rsp.getValues().get("response")).docs;
Document d = req.getSearcher().doc(dl.iterator().nextDoc());
// ensure field in fl is not lazy
assertFalse( ((Field) d.getField("test_hlt")).getClass().getSimpleName().equals("LazyField"));
assertFalse( ((Field) d.getField("title")).getClass().getSimpleName().equals("LazyField"));
req.close();
}
示例3: getDocListSize
import org.apache.solr.response.ResultContext; //导入依赖的package包/类
private int getDocListSize(String query)
{
SolrQueryRequest request = null;
try
{
request = this.getLocalSolrQueryRequest();
ModifiableSolrParams params = new ModifiableSolrParams(request.getParams());
params.set("q", query);
// Sets the rows to zero, because we actually just want the count
params.set("rows", 0);
ResultContext resultContext = cloud.getResultContext(nativeRequestHandler, request, params);
int matches = resultContext.docs.matches();
return matches;
}
finally
{
if (request != null) { request.close(); }
}
}
示例4: exists
import org.apache.solr.response.ResultContext; //导入依赖的package包/类
/**
* Returns whether or not a doc exists that satisfies the specified query
* @param requestHandler the handler that handles the request
* @param request the request object to put the query on
* @param query the string that specifies the doc
* @return <code>true</code> if the specified query returns a doc
*/
boolean exists(SolrRequestHandler requestHandler, SolrQueryRequest request, String query)
{
ModifiableSolrParams params = new ModifiableSolrParams(request.getParams());
// Sets 1 because this is effectively a boolean query to see if there exists a single match
params.set("q", query).set("fl", "id").set("rows", "1");
ResultContext rc = this.getResultContext(requestHandler, request, params);
if (rc != null)
{
// TODO Should we use rc.docs.matches() instead?
if (rc.docs != null) { return rc.docs.iterator().hasNext(); }
}
return false;
}
示例5: process
import org.apache.solr.response.ResultContext; //导入依赖的package包/类
@Override
public void process(ResponseBuilder rb) throws IOException {
SolrParams params = rb.req.getParams();
if (!params.getBool(COMPONENT_NAME, false)) return;
IndexSchema schema = rb.req.getSchema();
if (schema.getUniqueKeyField() == null) return;
ResultContext rc = (ResultContext) rb.rsp.getValues().get("response");
SolrIndexSearcher searcher = rb.req.getSearcher();
if (rc.docs.hasScores()) {
processScores(rb, rc.docs, schema, searcher);
} else {
processIds(rb, rc.docs, schema, searcher);
}
}
示例6: testUngrouped
import org.apache.solr.response.ResultContext; //导入依赖的package包/类
@Test
@SuppressWarnings("rawtypes")
public void testUngrouped() {
ModifiableSolrParams params = new ModifiableSolrParams();
NamedList results = test(params, "xjoin");
testXJoinResults(results, "xjoin");
ResultContext response = (ResultContext)results.get("response");
DocList docs = response.getDocList();
assertEquals(2, docs.size());
DocIterator it = docs.iterator();
assertTrue(it.hasNext());
assertEquals(1, it.nextDoc());
assertTrue(it.hasNext());
assertEquals(3, it.nextDoc());
assertFalse(it.hasNext());
}
示例7: testUngrouped
import org.apache.solr.response.ResultContext; //导入依赖的package包/类
@Test
@SuppressWarnings("rawtypes")
public void testUngrouped() {
ModifiableSolrParams params = new ModifiableSolrParams();
NamedList results = test(params, "xjoin");
testXJoinResults(results, "xjoin");
ResultContext response = (ResultContext)results.get("response");
DocList docs = response.docs;
assertEquals(2, docs.size());
DocIterator it = docs.iterator();
assertTrue(it.hasNext());
assertEquals(1, it.nextDoc());
assertTrue(it.hasNext());
assertEquals(3, it.nextDoc());
assertFalse(it.hasNext());
}
示例8: setUp
import org.apache.solr.response.ResultContext; //导入依赖的package包/类
@Before
public void setUp() {
rh1 = mock(SearchHandler.class);
rh2 = mock(SearchHandler.class);
rh3 = mock(SearchHandler.class);
qrequest = mock(SolrQueryRequest.class);
qresponse = mock(SolrQueryResponse.class);
args = new SimpleOrderedMap<>();
args.add(
InvisibleQueriesRequestHandler.CHAIN_KEY,
SAMPLE_VALID_CHAIN.stream().collect(joining(",")));
params = new ModifiableSolrParams().add(SAMPLE_KEY, SAMPLE_VALUE);
core = mock(SolrCore.class);
when(qrequest.getCore()).thenReturn(core);
when(core.getRequestHandler(REQUEST_HANDLER_1_NAME)).thenReturn(rh1);
when(core.getRequestHandler(REQUEST_HANDLER_2_NAME)).thenReturn(rh2);
when(core.getRequestHandler(REQUEST_HANDLER_3_NAME)).thenReturn(rh3);
cut = new InvisibleQueriesRequestHandler();
positiveResult = mock(ResultContext.class);
docList = mock(DocList.class);
when(docList.size()).thenReturn(1);
when(positiveResult.getDocList()).thenReturn(docList);
}
示例9: testGroupingSimpleFormatArrayIndexOutOfBoundsExceptionWithJavaBin
import org.apache.solr.response.ResultContext; //导入依赖的package包/类
@Test
public void testGroupingSimpleFormatArrayIndexOutOfBoundsExceptionWithJavaBin() throws Exception {
assertU(add(doc("id", "1", "nullfirst", "1")));
assertU(add(doc("id", "2", "nullfirst", "1")));
assertU(add(doc("id", "3", "nullfirst", "2")));
assertU(add(doc("id", "4", "nullfirst", "2")));
assertU(add(doc("id", "5", "nullfirst", "2")));
assertU(add(doc("id", "6", "nullfirst", "3")));
assertU(commit());
SolrQueryRequest request =
req("q", "*:*","group", "true", "group.field", "nullfirst", "group.main", "true", "wt", "javabin", "start", "4", "rows", "10");
SolrQueryResponse response = new SolrQueryResponse();
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(request, response));
String handlerName = request.getParams().get(CommonParams.QT);
h.getCore().execute(h.getCore().getRequestHandler(handlerName), request, response);
BinaryResponseWriter responseWriter = new BinaryResponseWriter();
responseWriter.write(out, request, response);
} finally {
request.close();
SolrRequestInfo.clearRequestInfo();
}
assertEquals(6, ((ResultContext) response.getValues().get("response")).docs.matches());
new BinaryResponseParser().processResponse(new ByteArrayInputStream(out.toByteArray()), "");
out.close();
}
示例10: getDocList
import org.apache.solr.response.ResultContext; //导入依赖的package包/类
/**
* Returns the doc list resulting from running the query
* @param requestHandler the handler that handles the request
* @param request the request object to put the query on
* @param query the string that specifies the docs
* @return the docs that come back from the query
*/
DocList getDocList(SolrRequestHandler requestHandler, SolrQueryRequest request, String query)
{
// Getting the doc list is shard-specific, and not really cloud-friendly
ModifiableSolrParams params = new ModifiableSolrParams(request.getParams());
// Sets MAX_VALUE to get all the rows
params.set("q", query).set("fl", QueryConstants.FIELD_SOLR4_ID).set("rows", Integer.MAX_VALUE);
ResultContext rc = this.getResultContext(requestHandler, request, params);
return rc != null ? rc.docs : null;
}
示例11: getResultContext
import org.apache.solr.response.ResultContext; //导入依赖的package包/类
/**
* @param requestHandler the handler that handles the request
* @param request the request object to put the params on
* @param params Solr parameters
* @return the result context from the handled request
*/
ResultContext getResultContext(SolrRequestHandler requestHandler, SolrQueryRequest request, SolrParams params)
{
SolrQueryResponse solrRsp = getResponse(requestHandler, request, params);
ResultContext rc = (ResultContext) solrRsp.getValues().get("response");
return rc;
}
示例12: testSelect
import org.apache.solr.response.ResultContext; //导入依赖的package包/类
@Test
public void testSelect()
{
SolrParams params = new ModifiableSolrParams(request.getParams());
ResultContext rc = cloud.getResultContext(super.aftsRequestHandler, request, params);
assertNull(rc);
}
示例13: testSimpleXJoinResultsFactory
import org.apache.solr.response.ResultContext; //导入依赖的package包/类
@Test
@SuppressWarnings("rawtypes")
public void testSimpleXJoinResultsFactory() {
ModifiableSolrParams params = new ModifiableSolrParams();
params.add("fl", "*, score");
params.add("xjoin", "false");
params.add("xjoin5", "true");
params.add("xjoin5.fl", "*");
// score boosts using value source parser
params.add("defType", "edismax");
params.add("bf", "xjoin5(value)");
NamedList results = test(params, "xjoin5");
ResultContext response = (ResultContext)results.get("response");
DocList docs = response.getDocList();
assertEquals(2, docs.size());
DocIterator it = docs.iterator();
assertTrue(it.hasNext());
assertEquals(0, it.nextDoc());
double score0 = it.score();
assertTrue(it.hasNext());
assertEquals(2, it.nextDoc());
double score2 = it.score();
assertFalse(it.hasNext());
// bf score boost for testid=0 only
assertTrue(score0 > score2);
List externalList = (List)((NamedList)results.get("xjoin5")).get("external");
NamedList hit0 = (NamedList)externalList.get(0);
assertEquals("0", hit0.get("joinId"));
NamedList doc0 = (NamedList)hit0.get("doc");
assertEquals("red", doc0.get("colour"));
assertEquals(10.5, doc0.get("value"));
}
示例14: testSimpleXJoinResultsFactory
import org.apache.solr.response.ResultContext; //导入依赖的package包/类
@Test
@SuppressWarnings("rawtypes")
public void testSimpleXJoinResultsFactory() {
ModifiableSolrParams params = new ModifiableSolrParams();
params.add("fl", "*, score");
params.add("xjoin", "false");
params.add("xjoin5", "true");
params.add("xjoin5.fl", "*");
// score boosts using value source parser
params.add("defType", "edismax");
params.add("bf", "xjoin5(value)");
NamedList results = test(params, "xjoin5");
ResultContext response = (ResultContext)results.get("response");
DocList docs = response.docs;
assertEquals(2, docs.size());
DocIterator it = docs.iterator();
assertTrue(it.hasNext());
assertEquals(0, it.nextDoc());
double score0 = it.score();
assertTrue(it.hasNext());
assertEquals(2, it.nextDoc());
double score2 = it.score();
assertFalse(it.hasNext());
// bf score boost for testid=0 only
assertTrue(score0 > score2);
List externalList = (List)((NamedList)results.get("xjoin5")).get("external");
NamedList hit0 = (NamedList)externalList.get(0);
assertEquals("0", hit0.get("joinId"));
NamedList doc0 = (NamedList)hit0.get("doc");
assertEquals("red", doc0.get("colour"));
assertEquals(10.5, doc0.get("value"));
}
示例15: setRescoredResults
import org.apache.solr.response.ResultContext; //导入依赖的package包/类
private void setRescoredResults(ResponseBuilder rb, TopDocs topDocs,
int offset, int len) {
DocListAndSet results = rb.getResults();
int totalHits = results.docList.matches();
int[] docs = new int[topDocs.scoreDocs.length];
float[] scores = new float[topDocs.scoreDocs.length];
for (int i = 0; i < topDocs.scoreDocs.length; i++) {
docs[i] = topDocs.scoreDocs[i].doc;
scores[i] = topDocs.scoreDocs[i].score;
}
results.docList = new DocSlice(offset, len, docs, scores, totalHits,
topDocs.getMaxScore());
ResultContext ctx = (ResultContext) rb.rsp.getValues().get("response");
ctx.docs = results.docList;
}