本文整理匯總了Java中org.apache.solr.response.SolrQueryResponse類的典型用法代碼示例。如果您正苦於以下問題:Java SolrQueryResponse類的具體用法?Java SolrQueryResponse怎麽用?Java SolrQueryResponse使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SolrQueryResponse類屬於org.apache.solr.response包,在下文中一共展示了SolrQueryResponse類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createResults
import org.apache.solr.response.SolrQueryResponse; //導入依賴的package包/類
protected SuggestionResult[] createResults(SolrQueryResponse rsp, String[] singlevalue_fields, String[] multivalue_fields, String query, String df, SuggestionRequestHandler.Type type, int termLimit, int limit, SuggestionRequestHandler.LimitType limitType, SuggestionRequestHandler.Strategy strategy, String sugestionField, Map<String, Map<String,Object>> intervals) {
SuggestionResult[] result = new SuggestionResult[2];
switch (type) {
case single:
result[0] = SuggestionResultFactory.createSingleValueResult(solrCore, rsp, singlevalue_fields, query, df, termLimit, limit, limitType, strategy,sugestionField,intervals);
break;
case multi:
result[1] = SuggestionResultFactory.createMultiValueResult(solrCore, rsp, multivalue_fields, query, df,termLimit, limit, limitType); //TODO consider strategy
break;
case mixed:
result[0] = SuggestionResultFactory.createSingleValueResult(solrCore, rsp, singlevalue_fields, query, df,termLimit, limit, limitType, strategy,sugestionField,intervals);
result[1] = SuggestionResultFactory.createMultiValueResult(solrCore, rsp, multivalue_fields, query, df, termLimit, limit, limitType);
}
if ((result[0] == null || result[0].getCount() ==0) && (result[1] == null || ((SuggestionResultMulti) result[1]).getCount() == 0)) {
result = null;
}
return result;
}
示例2: getMatchesFromQuery
import org.apache.solr.response.SolrQueryResponse; //導入依賴的package包/類
private RFResult getMatchesFromQuery(SolrQueryResponse rsp, SolrParams params, int flags, String q, Query query, Query userQuery, SortSpec sortSpec, List<Query> targetFqFilters, List<Query> rfFqFilters, SolrIndexSearcher searcher, RFHelper rfHelper, int start, int rows) throws IOException, SyntaxError {
boolean includeMatch = params.getBool(RFParams.MATCH_INCLUDE, true);
int matchOffset = params.getInt(RFParams.MATCH_OFFSET, 0);
// Find the base match
DocList match = searcher.getDocList(query, targetFqFilters, null, matchOffset, 10000, flags); // only get the first one...
if(match.matches() == 0 && userQuery == null){
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
String.format("RelevancyFeedback was unable to find any documents matching the query: '%s'.", q));
}
if (includeMatch) {
rsp.add("match", match);
}
// This is an iterator, but we only handle the first match
DocIterator iterator = match.iterator();
if (iterator.hasNext() || userQuery != null) {
// do a RelevancyFeedback query for each document in results
return rfHelper.getMatchesFromDocs(iterator, start, rows, rfFqFilters, flags, sortSpec.getSort(), userQuery);
}
return null;
}
示例3: test_QParserGetsCalled
import org.apache.solr.response.SolrQueryResponse; //導入依賴的package包/類
/**
* Basic test that checks that the "/similarity-query"
* defined in the resources/solrconfig.xml does set the query parser
* to the <code>{@link SimilarityParserPlugin}</code>
*/
public void test_QParserGetsCalled() throws Exception {
// arrange
SolrQueryRequest queryRequest = req("testQueryString");
// act
SolrQueryResponse resp = h.queryAndResponse("/similarity-query", queryRequest);
// assert - the only way to check that the similarity parser was used is to check
// the type of the query returned by the similarity parser (for a single term): AugmentedTermQuery
BasicResultContext basicResultContext = (BasicResultContext)resp.getResponse();
Query usedLuceneQuery = basicResultContext.getQuery();
assertTrue(usedLuceneQuery instanceof AugmentedTermQuery);
// cleanup
queryRequest.close();
}
開發者ID:sebastian-hofstaetter,項目名稱:ir-generalized-translation-models,代碼行數:23,代碼來源:SimilarityParserPluginIntegrationTest.java
示例4: test_QParserTwoTerms
import org.apache.solr.response.SolrQueryResponse; //導入依賴的package包/類
/**
* Checks that two terms are parsed and 2 <code>{@link AugmentedTermQuery}</code> inside
* 1 <code>{@link org.apache.lucene.search.BooleanQuery}</code> are returned.
* The schema.xml must define an analyzer for the default field defined in solrconfig.xml
*/
public void test_QParserTwoTerms() throws Exception {
// arrange
SolrQueryRequest queryRequest = req("good days");
// act
SolrQueryResponse resp = h.queryAndResponse("/similarity-query", queryRequest);
// assert - the only way to check that the similarity parser was used is to check
// the type of the query returned by the similarity parser (for a single term): AugmentedTermQuery
BasicResultContext basicResultContext = (BasicResultContext)resp.getResponse();
Query usedLuceneQuery = basicResultContext.getQuery();
assertTrue(usedLuceneQuery instanceof BooleanQuery);
BooleanQuery booleanQuery = (BooleanQuery) usedLuceneQuery;
assertEquals(2, booleanQuery.clauses().size());
assertTrue(booleanQuery.clauses().get(0).getQuery() instanceof AugmentedTermQuery);
assertTrue(booleanQuery.clauses().get(1).getQuery() instanceof AugmentedTermQuery);
// cleanup
queryRequest.close();
}
開發者ID:sebastian-hofstaetter,項目名稱:ir-generalized-translation-models,代碼行數:28,代碼來源:SimilarityParserPluginIntegrationTest.java
示例5: test_QParserTwoTerms_ET
import org.apache.solr.response.SolrQueryResponse; //導入依賴的package包/類
/**
* Checks that two terms are parsed and 2 <code>{@link AugmentedTermQuery}</code> inside
* 1 <code>{@link org.apache.lucene.search.BooleanQuery}</code> are returned.
* The schema.xml must define an analyzer for the default field defined in solrconfig.xml
*/
public void test_QParserTwoTerms_ET() throws Exception {
// arrange
SolrQueryRequest queryRequest = req("good days");
// act
SolrQueryResponse resp = h.queryAndResponse("/similarity-query-et", queryRequest);
// assert - the only way to check that the similarity parser was used is to check
// the type of the query returned by the similarity parser (for a single term): AugmentedTermQuery
BasicResultContext basicResultContext = (BasicResultContext)resp.getResponse();
Query usedLuceneQuery = basicResultContext.getQuery();
assertTrue(usedLuceneQuery instanceof BooleanQuery);
BooleanQuery booleanQuery = (BooleanQuery) usedLuceneQuery;
assertEquals(2, booleanQuery.clauses().size());
assertTrue(booleanQuery.clauses().get(0).getQuery() instanceof AugmentedTermQuery);
assertTrue(booleanQuery.clauses().get(1).getQuery() instanceof AugmentedTermQuery);
// cleanup
queryRequest.close();
}
開發者ID:sebastian-hofstaetter,項目名稱:ir-generalized-translation-models,代碼行數:28,代碼來源:SimilarityParserPluginIntegrationTest.java
示例6: firstRingAnswersSkipRemainingHandlers
import org.apache.solr.response.SolrQueryResponse; //導入依賴的package包/類
/**
* If the first handler in the chain answers with a no-zero result, then the rest of the chain has to be skept.
*
* @throws Exception hopefully never, otherwise the test fails.
*/
@Test
public void firstRingAnswersSkipRemainingHandlers() throws Exception {
doAnswer(new Answer<Void>() {
public Void answer(final InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
final SolrQueryResponse response = (SolrQueryResponse) args[1];
response.addResponse(positiveResult);
return null;
}})
.when(rh1).handleRequest(any(SolrQueryRequest.class), any(SolrQueryResponse.class));
cut.init(args);
cut.handleRequestBody(qrequest, qresponse);
verify(rh1).handleRequest(any(SolrQueryRequest.class), any(SolrQueryResponse.class));
verifyZeroInteractions(rh2,rh3);
}
示例7: secondRingAnswersSkipRemainingHandlers
import org.apache.solr.response.SolrQueryResponse; //導入依賴的package包/類
/**
* If the second handler in the chain answers with a no-zero result, then the rest of the chain has to be skept.
*
* @throws Exception hopefully never, otherwise the test fails.
*/
@Test
public void secondRingAnswersSkipRemainingHandlers() throws Exception {
doAnswer(new Answer<Void>() {
public Void answer(final InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
final SolrQueryResponse response = (SolrQueryResponse) args[1];
response.addResponse(positiveResult);
return null;
}})
.when(rh2).handleRequest(any(SolrQueryRequest.class), any(SolrQueryResponse.class));
cut.init(args);
cut.handleRequestBody(qrequest, qresponse);
verify(rh1).handleRequest(any(SolrQueryRequest.class), any(SolrQueryResponse.class));
verify(rh2).handleRequest(any(SolrQueryRequest.class), any(SolrQueryResponse.class));
verifyZeroInteractions(rh3);
}
示例8: thirdRingAnswersSkipRemainingHandlers
import org.apache.solr.response.SolrQueryResponse; //導入依賴的package包/類
/**
* If the third handler in the chain answers with a no-zero result, then all handlers need to be invoked.
*
* @throws Exception hopefully never, otherwise the test fails.
*/
@Test
public void thirdRingAnswersSkipRemainingHandlers() throws Exception {
doAnswer(new Answer<Void>() {
public Void answer(final InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
final SolrQueryResponse response = (SolrQueryResponse) args[1];
response.addResponse(positiveResult);
return null;
}})
.when(rh3).handleRequest(any(SolrQueryRequest.class), any(SolrQueryResponse.class));
cut.init(args);
cut.handleRequestBody(qrequest, qresponse);
verify(rh1).handleRequest(any(SolrQueryRequest.class), any(SolrQueryResponse.class));
verify(rh2).handleRequest(any(SolrQueryRequest.class), any(SolrQueryResponse.class));
verify(rh3).handleRequest(any(SolrQueryRequest.class), any(SolrQueryResponse.class));
}
示例9: setUp
import org.apache.solr.response.SolrQueryResponse; //導入依賴的package包/類
@Before
public void setUp() {
rh1 = mock(SearchHandler.class);
rh2 = mock(SearchHandler.class);
rh3 = mock(SearchHandler.class);
cut = new InvisibleQueriesRequestHandler();
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);
}
開發者ID:spaziocodice,項目名稱:invisible-queries-request-handler,代碼行數:19,代碼來源:FacadeRequestHandlerTestCase.java
示例10: handleSuggestionHitsRequest
import org.apache.solr.response.SolrQueryResponse; //導入依賴的package包/類
public long handleSuggestionHitsRequest(ReSearcherRequestContext ctx, String query, Set<String> componentNames) throws Exception {
ModifiableSolrParams params = new ModifiableSolrParams(ctx.getParams());
params.set(CommonParams.ROWS, "0");
for(String componentName : componentNames) {
params.set(componentName, "false");
}
params.set(CommonParams.Q, query);
SolrQueryRequest req = new SolrQueryRequestBase(ctx.getCore(), params) {};
SolrQueryResponse rsp = new SolrQueryResponse();
ResponseBuilder rb = new ResponseBuilder(req, rsp, ctx.getQueryOnlyComponents());
try {
handleSuggestionRequest(ctx, rb, ctx.getQueryOnlyComponents(), true);
} finally {
req.close();
}
return ReSearcherUtils.extractOriginalQueryHits(rb);
}
示例11: init
import org.apache.solr.response.SolrQueryResponse; //導入依賴的package包/類
@Before
public void init()
{
new MockUp<SolrQueryResponse>()
{
@Mock public NamedList<Object> getResponseHeader()
{
NamedList<Object> headers = new NamedList<>();
headers.add("status", 400);
return headers;
}
};
request = new LocalSolrQueryRequest(null, dummy);
response = new SolrQueryResponse();
response.setHttpHeader("status", "400");
}
開發者ID:careerbuilder,項目名稱:semantic-knowledge-graph,代碼行數:18,代碼來源:KnowledgeGraphResponseWriterTest.java
示例12: handleRequestBody
import org.apache.solr.response.SolrQueryResponse; //導入依賴的package包/類
/**
* Handles three types of requests.
* <ol>
* <li>search by already extracted images.</li>
* <li>search by an image URL.</li>
* <li>Random results.</li>
* </ol>
*
* @param req
* @param rsp
* @throws Exception
*/
@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
// (1) check if the necessary parameters are here
if (req.getParams().get("hashes") != null) { // we are searching for hashes ...
handleHashSearch(req, rsp); // not really supported, just here for legacy.
} else if (req.getParams().get("url") != null) { // we are searching for an image based on an URL
handleUrlSearch(req, rsp);
} else if (req.getParams().get("id") != null) { // we are searching for an image based on an URL
handleIdSearch(req, rsp);
} else if (req.getParams().get("extract") != null) { // we are trying to extract from an image URL.
handleExtract(req, rsp);
} else { // lets return random results.
handleRandomSearch(req, rsp);
}
}
示例13: handleRandomSearch
import org.apache.solr.response.SolrQueryResponse; //導入依賴的package包/類
/**
* Returns a random set of documents from the index. Mainly for testing purposes.
*
* @param req
* @param rsp
* @throws IOException
*/
private void handleRandomSearch(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException {
SolrIndexSearcher searcher = req.getSearcher();
Query query = new MatchAllDocsQuery();
DocList docList = searcher.getDocList(query, getFilterQueries(req), Sort.RELEVANCE, 0, numberOfCandidateResults, 0);
int paramRows = Math.min(req.getParams().getInt("rows", defaultNumberOfResults), docList.size());
if (docList.size() < 1) {
rsp.add("Error", "No documents in index");
} else {
LinkedList list = new LinkedList();
while (list.size() < paramRows) {
DocList auxList = docList.subset((int) (Math.random() * docList.size()), 1);
Document doc = null;
for (DocIterator it = auxList.iterator(); it.hasNext(); ) {
doc = searcher.doc(it.nextDoc());
}
if (!list.contains(doc)) {
list.add(doc);
}
}
rsp.addResponse(list);
}
}
示例14: getInstance
import org.apache.solr.response.SolrQueryResponse; //導入依賴的package包/類
@Override
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
SolrQueryResponse rsp,
UpdateRequestProcessor next) {
final IndexSchema schema = req.getSchema();
return new FieldMutatingUpdateProcessor(getSelector(), next) {
@Override
protected SolrInputField mutate(SolrInputField src) {
if (src.getValueCount() <= 1)
return src;//short circuit single value
SchemaField field = schema.getField(src.getName());
FieldType ft = field.getType();
IndexableField result = ft.createField(field, src, src.getBoost());
if (result == null)
return null;//remove
src.setValue(result, src.getBoost());
return src;
}
};
}
示例15: doCompact
import org.apache.solr.response.SolrQueryResponse; //導入依賴的package包/類
private void doCompact(LazyDocumentLoader documentLoader,
LazyCompactor compactor,
SolrQueryResponse rsp,
String tsId,
String q) throws IOException, SyntaxError {
Query query = depProvider.parser(q).getQuery();
Iterable<Document> docs = documentLoader.load(query, SORT);
Iterable<CompactionResult> compactionResults = compactor.compact(docs);
List<Document> docsToDelete = new LinkedList<>();
List<SolrInputDocument> docsToAdd = new LinkedList<>();
compactionResults.forEach(it -> {
docsToDelete.addAll(it.getInputDocuments());
docsToAdd.addAll(it.getOutputDocuments());
});
depProvider.solrUpdateService().add(docsToAdd);
depProvider.solrUpdateService().delete(docsToDelete);
rsp.add("timeseries " + tsId + " oldNumDocs:", docsToDelete.size());
rsp.add("timeseries " + tsId + " newNumDocs:", docsToAdd.size());
}