本文整理匯總了Java中org.apache.solr.response.SolrQueryResponse.getValues方法的典型用法代碼示例。如果您正苦於以下問題:Java SolrQueryResponse.getValues方法的具體用法?Java SolrQueryResponse.getValues怎麽用?Java SolrQueryResponse.getValues使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.solr.response.SolrQueryResponse
的用法示例。
在下文中一共展示了SolrQueryResponse.getValues方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testXPath
import org.apache.solr.response.SolrQueryResponse; //導入方法依賴的package包/類
@Test
public void testXPath() throws Exception {
ExtractingRequestHandler handler = (ExtractingRequestHandler) h.getCore().getRequestHandler("/update/extract");
assertTrue("handler is null and it shouldn't be", handler != null);
SolrQueryResponse rsp = loadLocal("extraction/example.html",
ExtractingParams.XPATH_EXPRESSION, "/xhtml:html/xhtml:body/xhtml:a/descendant::node()",
ExtractingParams.EXTRACT_ONLY, "true"
);
assertTrue("rsp is null and it shouldn't be", rsp != null);
NamedList list = rsp.getValues();
String val = (String) list.get("example.html");
assertEquals("News", val.trim()); //there is only one matching <a> tag
loadLocal("extraction/example.html",
"literal.id", "example1",
"captureAttr", "true",
"defaultField", "text",
"capture", "div",
"fmap.div", "foo_t",
"boost.foo_t", "3",
"xpath", "/xhtml:html/xhtml:body/xhtml:div//node()",
"commit", "true"
);
assertQ(req("+id:example1 +foo_t:\"here is some text in a div\""), "//*[@numFound='1']");
}
示例2: executeQuery
import org.apache.solr.response.SolrQueryResponse; //導入方法依賴的package包/類
/**
* Executes the given handler (query) logic.
* @param request the current {@link SolrQueryRequest}.
* @param response the current {@link SolrQueryResponse}.
* @param params the request parameters.
* @param handler the executor handler.
* @return the query response, that is, the result of the handler's query execution.
*/
@SuppressWarnings("unchecked")
NamedList<Object> executeQuery(
final SolrQueryRequest request,
final SolrQueryResponse response,
final SolrParams params,
final SolrRequestHandler handler) {
try(final SolrQueryRequest scopedRequest = newFrom(request, params)) {
final SolrQueryResponse scopedResponse = newFrom(response);
handler.handleRequest(
scopedRequest,
scopedResponse);
return scopedResponse.getValues();
}
}
開發者ID:spaziocodice,項目名稱:invisible-queries-request-handler,代碼行數:23,代碼來源:InvisibleQueriesRequestHandler.java
示例3: testFusionResponseProcessing
import org.apache.solr.response.SolrQueryResponse; //導入方法依賴的package包/類
public void testFusionResponseProcessing() throws Exception {
String typicalFusionResponse = "{ \n" +
" \"fusion\" : {\n" +
" \"query-params\": {\n" +
" \"extra\": [\"test\"],\n" +
" \"extrarray\": [\"test1\",\"test2\"]\n" +
" },\n" +
" \"landing-pages\": [\n" +
" \"www.lucidworks.com\"\n" +
" ]\n" +
" }\n" +
"}";
SolrQueryRequest req = new LocalSolrQueryRequest(null, new NamedList());
SolrQueryResponse rsp = new SolrQueryResponse();
FusionQPSearchComponent.overlayFusionData(typicalFusionResponse, req, rsp);
// test query params made it to the request
SolrParams p = req.getParams();
assertEquals("test", p.getParams("extra")[0]);
assertEquals("test1", p.getParams("extrarray")[0]);
assertEquals("test2", p.getParams("extrarray")[1]);
// check that everything else passed through into the response
NamedList nl = rsp.getValues();
ArrayList landingPages = (ArrayList)((NamedList)nl.get("fusion")).get("landing-pages");
assertNotNull(landingPages);
assertEquals("www.lucidworks.com", landingPages.get(0));
}
示例4: testExtractOnly
import org.apache.solr.response.SolrQueryResponse; //導入方法依賴的package包/類
@Test
public void testExtractOnly() throws Exception {
ExtractingRequestHandler handler = (ExtractingRequestHandler) h.getCore().getRequestHandler("/update/extract");
assertTrue("handler is null and it shouldn't be", handler != null);
SolrQueryResponse rsp = loadLocal("extraction/solr-word.pdf", ExtractingParams.EXTRACT_ONLY, "true");
assertTrue("rsp is null and it shouldn't be", rsp != null);
NamedList list = rsp.getValues();
String extraction = (String) list.get("solr-word.pdf");
assertTrue("extraction is null and it shouldn't be", extraction != null);
assertTrue(extraction + " does not contain " + "solr-word", extraction.indexOf("solr-word") != -1);
NamedList nl = (NamedList) list.get("solr-word.pdf_metadata");
assertTrue("nl is null and it shouldn't be", nl != null);
Object title = nl.get("title");
assertTrue("title is null and it shouldn't be", title != null);
assertTrue(extraction.indexOf("<?xml") != -1);
rsp = loadLocal("extraction/solr-word.pdf", ExtractingParams.EXTRACT_ONLY, "true",
ExtractingParams.EXTRACT_FORMAT, ExtractingDocumentLoader.TEXT_FORMAT);
assertTrue("rsp is null and it shouldn't be", rsp != null);
list = rsp.getValues();
extraction = (String) list.get("solr-word.pdf");
assertTrue("extraction is null and it shouldn't be", extraction != null);
assertTrue(extraction + " does not contain " + "solr-word", extraction.indexOf("solr-word") != -1);
assertTrue(extraction.indexOf("<?xml") == -1);
nl = (NamedList) list.get("solr-word.pdf_metadata");
assertTrue("nl is null and it shouldn't be", nl != null);
title = nl.get("title");
assertTrue("title is null and it shouldn't be", title != null);
}
示例5: testCollateWithFilter
import org.apache.solr.response.SolrQueryResponse; //導入方法依賴的package包/類
@Test
public void testCollateWithFilter() throws Exception
{
SolrCore core = h.getCore();
SearchComponent speller = core.getSearchComponent("spellcheck");
assertTrue("speller is null and it shouldn't be", speller != null);
ModifiableSolrParams params = new ModifiableSolrParams();
params.add(SpellCheckComponent.COMPONENT_NAME, "true");
params.add(SpellingParams.SPELLCHECK_BUILD, "true");
params.add(SpellingParams.SPELLCHECK_COUNT, "10");
params.add(SpellingParams.SPELLCHECK_COLLATE, "true");
params.add(SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "10");
params.add(SpellingParams.SPELLCHECK_MAX_COLLATIONS, "10");
params.add(CommonParams.Q, "lowerfilt:(+fauth +home +loane)");
params.add(CommonParams.FQ, "NOT(id:1)");
//Because a FilterQuery is applied which removes doc id#1 from possible hits, we would
//not want the collations to return us "lowerfilt:(+faith +hope +loaves)" as this only matches doc id#1.
SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
SolrQueryResponse rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
handler.handleRequest(req, rsp);
req.close();
NamedList values = rsp.getValues();
NamedList spellCheck = (NamedList) values.get("spellcheck");
NamedList suggestions = (NamedList) spellCheck.get("suggestions");
List<String> collations = suggestions.getAll("collation");
assertTrue(collations.size() > 0);
for(String collation : collations) {
assertTrue(!collation.equals("lowerfilt:(+faith +hope +loaves)"));
}
}
示例6: testCollateWithGrouping
import org.apache.solr.response.SolrQueryResponse; //導入方法依賴的package包/類
@Test
public void testCollateWithGrouping() throws Exception
{
SolrCore core = h.getCore();
SearchComponent speller = core.getSearchComponent("spellcheck");
assertTrue("speller is null and it shouldn't be", speller != null);
ModifiableSolrParams params = new ModifiableSolrParams();
params.add(SpellCheckComponent.COMPONENT_NAME, "true");
params.add(SpellingParams.SPELLCHECK_BUILD, "true");
params.add(SpellingParams.SPELLCHECK_COUNT, "10");
params.add(SpellingParams.SPELLCHECK_COLLATE, "true");
params.add(SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "5");
params.add(SpellingParams.SPELLCHECK_MAX_COLLATIONS, "1");
params.add(CommonParams.Q, "lowerfilt:(+fauth)");
params.add(GroupParams.GROUP, "true");
params.add(GroupParams.GROUP_FIELD, "id");
//Because a FilterQuery is applied which removes doc id#1 from possible hits, we would
//not want the collations to return us "lowerfilt:(+faith +hope +loaves)" as this only matches doc id#1.
SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
SolrQueryResponse rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
handler.handleRequest(req, rsp);
req.close();
NamedList values = rsp.getValues();
NamedList spellCheck = (NamedList) values.get("spellcheck");
NamedList suggestions = (NamedList) spellCheck.get("suggestions");
List<String> collations = suggestions.getAll("collation");
assertTrue(collations.size() == 1);
}
示例7: testZeroTries
import org.apache.solr.response.SolrQueryResponse; //導入方法依賴的package包/類
@Test
public void testZeroTries() throws Exception
{
SolrCore core = h.getCore();
SearchComponent speller = core.getSearchComponent("spellcheck");
assertTrue("speller is null and it shouldn't be", speller != null);
ModifiableSolrParams params = new ModifiableSolrParams();
params.add(SpellCheckComponent.COMPONENT_NAME, "true");
params.add(SpellCheckComponent.SPELLCHECK_BUILD, "true");
params.add(SpellCheckComponent.SPELLCHECK_COUNT, "10");
params.add(SpellCheckComponent.SPELLCHECK_COLLATE, "true");
params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATION_TRIES, "0");
params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATIONS, "2");
params.add(CommonParams.Q, "lowerfilt:(+fauth)");
SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
SolrQueryResponse rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
handler.handleRequest(req, rsp);
req.close();
NamedList values = rsp.getValues();
NamedList spellCheck = (NamedList) values.get("spellcheck");
NamedList suggestions = (NamedList) spellCheck.get("suggestions");
List<String> collations = suggestions.getAll("collation");
assertTrue(collations.size() == 2);
}
示例8: assertSchemaResource
import org.apache.solr.response.SolrQueryResponse; //導入方法依賴的package包/類
private void assertSchemaResource(String collection, String expectedSchemaResource) throws Exception {
final CoreContainer cores = h.getCoreContainer();
final CoreAdminHandler admin = new CoreAdminHandler(cores);
SolrQueryRequest request = req(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.STATUS.toString());
SolrQueryResponse response = new SolrQueryResponse();
admin.handleRequestBody(request, response);
assertNull("Exception on create", response.getException());
NamedList responseValues = response.getValues();
NamedList status = (NamedList)responseValues.get("status");
NamedList collectionStatus = (NamedList)status.get(collection);
String collectionSchema = (String)collectionStatus.get(CoreAdminParams.SCHEMA);
assertEquals("Schema resource name differs from expected name", expectedSchemaResource, collectionSchema);
}
示例9: write
import org.apache.solr.response.SolrQueryResponse; //導入方法依賴的package包/類
/**
* Here the writer creates its output.
*
* @param writer the character stream writer.
* @param request the current {@link SolrQueryRequest}
* @param response the output response.
* @throws IOException in case of I/O failure.
*/
@SuppressWarnings("rawtypes")
@Override
public void write(
final Writer writer,
final SolrQueryRequest request,
final SolrQueryResponse response) throws IOException {
// 1. Get a reference to values that compound the current response
final NamedList elements = response.getValues();
// 2. Use a StringBuilder to build the output
final StringBuilder builder = new StringBuilder("{")
.append("query:'")
.append(request.getParams().get(CommonParams.Q))
.append("',");
// 3. Get a reference to the object which hold the query result
final Object value = elements.getVal(1);
if (value instanceof ResultContext) {
final ResultContext context = (ResultContext) value;
// The ordered list (actually the page subset) of matched documents
final DocList ids = context.getDocList();
if (ids != null) {
final SolrIndexSearcher searcher = request.getSearcher();
final DocIterator iterator = ids.iterator();
builder.append("suggestions:[");
// 4. Iterate over documents
for (int i = 0; i < ids.size(); i++) {
// 5. For each document we need to get the corresponding "label" attribute
final Document document = searcher.doc(iterator.nextDoc(), FIELDS);
if (i > 0) { builder.append(","); }
// 6. Append the label value to writer output
builder
.append("'")
.append(((String) document.get("label")).replaceAll("'", "\\\\'").replaceAll("\"", "\\\\\""))
.append("'");
}
builder.append("]").append("}");
}
}
// 7. and finally write out the built character stream by means of output writer.
writer.write(builder.toString());
}