本文整理匯總了Java中org.apache.solr.client.solrj.response.QueryResponse.getResults方法的典型用法代碼示例。如果您正苦於以下問題:Java QueryResponse.getResults方法的具體用法?Java QueryResponse.getResults怎麽用?Java QueryResponse.getResults使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.solr.client.solrj.response.QueryResponse
的用法示例。
在下文中一共展示了QueryResponse.getResults方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import org.apache.solr.client.solrj.response.QueryResponse; //導入方法依賴的package包/類
public static void main(String[] args) throws MalformedURLException, SolrServerException {
String zkHost = "localhost:2181";
String defaultCollection = "collection1";
CloudSolrServer solr = new CloudSolrServer(zkHost);
solr.setDefaultCollection(defaultCollection);
/* ModifiableSolrParams params = new ModifiableSolrParams();
params.set("q", "cat:electronics");
params.set("defType", "edismax");
params.set("start", "0");*/
SolrQuery params = new SolrQuery();
params.setQuery("*:*");
params.setSort("score ",ORDER.desc);
params.setStart(Integer.getInteger("0"));
params.setRows(Integer.getInteger("100"));
QueryResponse response = solr.query(params);
SolrDocumentList results = response.getResults();
for (int i = 0; i < results.size(); ++i) {
System.out.println(results.get(i));
}
}
示例2: getAllIndexedDocs
import org.apache.solr.client.solrj.response.QueryResponse; //導入方法依賴的package包/類
public List<Map<String, Object>> getAllIndexedDocs(String collection) {
List<Map<String, Object>> docs = new ArrayList<>();
CloudSolrClient solr = miniSolrCloudCluster.getSolrClient();
solr.setDefaultCollection(collection);
SolrQuery parameters = new SolrQuery();
parameters.set("q", "*:*");
try {
solr.commit();
QueryResponse response = solr.query(parameters);
for (SolrDocument solrDocument : response.getResults()) {
docs.add(solrDocument);
}
} catch (SolrServerException | IOException e) {
e.printStackTrace();
}
return docs;
}
示例3: main
import org.apache.solr.client.solrj.response.QueryResponse; //導入方法依賴的package包/類
public static void main(String[] args) throws MalformedURLException, SolrServerException {
HttpSolrServer solr = new HttpSolrServer("http://localhost:8983/solr");
// ModifiableSolrParams params = new ModifiableSolrParams();
// params.setQuery("name:Samsung ");
// params.setStart(0);
// params.setRows(100);
SolrQuery params = new SolrQuery();
params.setQuery("*:*");
params.setSort("score ",ORDER.desc);
params.setStart(Integer.getInteger("0"));
params.setRows(Integer.getInteger("100"));
QueryResponse response = solr.query(params);
SolrDocumentList results = response.getResults();
for (int i = 0; i < results.size(); ++i) {
System.out.println(results.get(i));
}
}
示例4: search
import org.apache.solr.client.solrj.response.QueryResponse; //導入方法依賴的package包/類
/**
* searches and returns a list of {@link SolrDocument}
*
* @param from startdate
* @param until enddate
* @param set which collection
* @param metadataPrefix
* @param firstRow
* @param numRows
* @param urnOnly
* @param querySuffix
* @return list of hits as {@link SolrDocument}
* @throws IOException
* @throws SolrServerException
*/
public SolrDocumentList search(String from, String until, String set, String metadataPrefix, int firstRow, int numRows, boolean urnOnly,
String querySuffix) throws IOException, SolrServerException {
StringBuilder sbQuery = new StringBuilder(buildQueryString(from, until, set, metadataPrefix, urnOnly, querySuffix));
if (urnOnly) {
sbQuery.append(" AND (").append(SolrConstants.URN).append(":* OR ").append(SolrConstants.IMAGEURN_OAI).append(":*)");
}
sbQuery.append(getAllSuffixes());
logger.debug("OAI query: {}", sbQuery.toString());
SolrQuery solrQuery = new SolrQuery(sbQuery.toString());
solrQuery.setStart(firstRow);
solrQuery.setRows(numRows);
solrQuery.addSort(SolrConstants.DATECREATED, ORDER.asc);
QueryResponse resp = server.query(solrQuery);
logger.debug("Total hits: {}, fetched records {} - {}", resp.getResults().getNumFound(), firstRow, firstRow + resp.getResults().size() - 1);
return resp.getResults();
}
示例5: query
import org.apache.solr.client.solrj.response.QueryResponse; //導入方法依賴的package包/類
/**
*
* @param identifier
* @param metadataPrefix
* @param rows
* @return
* @throws SolrServerException
*/
private SolrDocumentList query(final String identifier, String metadataPrefix, int rows) throws SolrServerException {
String useIdentifier = ClientUtils.escapeQueryChars(identifier);
StringBuilder sb = new StringBuilder();
sb.append('(').append(SolrConstants.PI).append(':').append(useIdentifier).append(" OR ").append(SolrConstants.URN).append(':').append(
useIdentifier).append(" OR ").append(SolrConstants.IMAGEURN).append(':').append(useIdentifier).append(')');
sb.append(getAllSuffixes());
logger.debug(sb.toString());
SolrQuery solrQuery = new SolrQuery(sb.toString());
solrQuery.setRows(rows);
QueryResponse resp = server.query(solrQuery);
// if (resp.getResults().isEmpty() && Metadata.epicur.name().equals(metadataPrefix)) {
// solrQuery = new SolrQuery(new StringBuilder(SolrConstants.IMAGEURN_OAI).append(":").append(identifier).toString());
// solrQuery.setRows(rows);
// resp = server.query(solrQuery);
// }
return resp.getResults();
}
示例6: readNextPage
import org.apache.solr.client.solrj.response.QueryResponse; //導入方法依賴的package包/類
private boolean readNextPage() {
if (totalCountOfRows < 0 || startOfCurrentPage < totalCountOfRows) {
mySolrQuery.set("start", startOfCurrentPage);
mySolrQuery.set("rows", pageSize);
startOfCurrentPage += pageSize;
QueryResponse rsp = null;
List<Object[]> rows = new ArrayList<>();
try {
rsp = solrClientFactory.getClient().query(mySolrQuery);
SolrDocumentList docs = rsp.getResults();
totalCountOfRows = docs.getNumFound();
for (SolrDocument doc : docs) {
rows.add(doc2Row(doc));
}
} catch (Exception e) {
logger.error(e);
}
rowIteratorWithinCurrentPage = rows.iterator();
return true;
}
return false;
}
示例7: responseIs
import org.apache.solr.client.solrj.response.QueryResponse; //導入方法依賴的package包/類
private synchronized boolean responseIs( QueryResponse rsp, String field, String ... queries ) {
System.out.println( field + " " + rsp.getResults( ).size( ) );
HashSet<String> expected = new HashSet<String>( );
for ( int i = 0; i < queries.length; i++) {
System.out.println( "adding '" + queries[i] + "'" );
expected.add( queries[i] );
}
for (SolrDocument doc : rsp.getResults() ) {
String val = String.valueOf( doc.getFirstValue( field ) );
System.out.println( " '" + val + "'" );
if (expected.contains( val )) {
System.out.println( "removing '" + val + "'" );
expected.remove( val );
}
}
System.out.println( expected.size( ) + " left " );
return expected.size() == 0;
}
示例8: getHeader
import org.apache.solr.client.solrj.response.QueryResponse; //導入方法依賴的package包/類
@Override
public Optional<Header> getHeader(String mcrId) {
SolrQuery query = getBaseQuery(CommonParams.FQ);
query.set(CommonParams.Q, "id:" + MCRSolrUtils.escapeSearchValue(mcrId));
query.setRows(1);
// do the query
SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
try {
QueryResponse response = solrClient.query(query);
SolrDocumentList results = response.getResults();
if (!results.isEmpty()) {
return Optional.of(toHeader(results.get(0), getSetResolver(results)));
}
} catch (Exception exc) {
LOGGER.error("Unable to handle solr request", exc);
}
return Optional.empty();
}
示例9: getEarliestTimestamp
import org.apache.solr.client.solrj.response.QueryResponse; //導入方法依賴的package包/類
@Override
public Optional<Instant> getEarliestTimestamp() {
String sortBy = getConfig().getString(getConfigPrefix() + "EarliestDatestamp.SortBy", "modified asc");
String fieldName = getConfig().getString(getConfigPrefix() + "EarliestDatestamp.FieldName", "modified");
String restriction = getConfig().getString(getConfigPrefix() + "Search.Restriction", null);
ModifiableSolrParams params = new ModifiableSolrParams();
params.add(CommonParams.SORT, sortBy);
params.add(CommonParams.Q, restriction);
params.add(CommonParams.FQ, fieldName + ":[* TO *]");
params.add(CommonParams.FL, fieldName);
params.add(CommonParams.ROWS, "1");
SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
try {
QueryResponse response = solrClient.query(params);
SolrDocumentList list = response.getResults();
if (list.size() >= 1) {
Date date = (Date) list.get(0).getFieldValue(fieldName);
return Optional.of(date.toInstant());
}
} catch (Exception exc) {
LOGGER.error("Unable to handle solr request", exc);
}
return Optional.empty();
}
示例10: filterNonEmpty
import org.apache.solr.client.solrj.response.QueryResponse; //導入方法依賴的package包/類
private void filterNonEmpty(String classId, Element e) {
SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
for (int i = 0; i < e.getChildren("category").size(); i++) {
Element cat = e.getChildren("category").get(i);
SolrQuery solrQquery = new SolrQuery();
solrQquery.setQuery(
"category:\"" + MCRSolrUtils.escapeSearchValue(classId + ":" + cat.getAttributeValue("ID")) + "\"");
solrQquery.setRows(0);
try {
QueryResponse response = solrClient.query(solrQquery);
SolrDocumentList solrResults = response.getResults();
if (solrResults.getNumFound() == 0) {
e.removeContent(cat);
i--;
}
} catch (SolrServerException | IOException exc) {
LOGGER.error(exc);
}
}
for (int i = 0; i < e.getChildren("category").size(); i++) {
filterNonEmpty(classId, e.getChildren("category").get(i));
}
}
示例11: printRanking
import org.apache.solr.client.solrj.response.QueryResponse; //導入方法依賴的package包/類
/**
* Ausgabe des Suchtreffer im Ranking
* @param response
*/
private void printRanking(QueryResponse response) {
if (response != null) {
SolrDocumentList results = response.getResults();
if (results.isEmpty()) {
System.out.println("Ihre Suchanfrage ergab leider keine Treffer. Bitte modifizieren Sie ihre Anfrage.");
}
else {
System.out.println("Trefferanzahl: " + results.getNumFound());
System.out.println("~~~~~~~~~ Trefferliste ~~~~~~~");
int rank = 1;
for (SolrDocument doc : results) {
System.out.println("Treffer #" + rank);
System.out.println("\tID: " + doc.get("id"));
System.out.println("\tTitel: " + doc.get("title"));
// TODO weitere Indexfelder (mit stored=true) ausgeben
System.out.println("\tScore: " + doc.get("score"));
System.out.println("\n- - - - - - - - - - -");
rank++;
}
}
}
}
示例12: testSimple
import org.apache.solr.client.solrj.response.QueryResponse; //導入方法依賴的package包/類
public void testSimple() throws Exception {
DocumentObjectBinder binder = new DocumentObjectBinder();
XMLResponseParser parser = new XMLResponseParser();
NamedList<Object> nl = parser.processResponse(new StringReader(xml));
QueryResponse res = new QueryResponse(nl, null);
SolrDocumentList solDocList = res.getResults();
List<Item> l = binder.getBeans(Item.class,res.getResults());
assertEquals(solDocList.size(), l.size());
assertEquals(solDocList.get(0).getFieldValue("features"), l.get(0).features);
Item item = new Item();
item.id = "aaa";
item.categories = new String[] {"aaa", "bbb", "ccc"};
SolrInputDocument out = binder.toSolrInputDocument(item);
assertEquals(item.id, out.getFieldValue("id"));
SolrInputField catfield = out.getField("cat");
assertEquals(3, catfield.getValueCount());
List<String> catValues = (List<String>) catfield.getValue();
assertEquals("aaa", catValues.get(0));
assertEquals("bbb", catValues.get(1));
assertEquals("ccc", catValues.get(2));
}
示例13: emitTuples
import org.apache.solr.client.solrj.response.QueryResponse; //導入方法依賴的package包/類
@Override
public void emitTuples()
{
SolrParams solrQueryParams = getQueryParams();
try {
SolrServer solrServer = solrServerConnector.getSolrServer();
QueryResponse response = solrServer.query(solrQueryParams);
SolrDocumentList queriedDocuments = response.getResults();
for (SolrDocument solrDocument : queriedDocuments) {
emitTuple(solrDocument);
lastEmittedTuple = solrDocument;
lastEmittedTimeStamp = System.currentTimeMillis();
logger.debug("Emiting document: " + solrDocument.getFieldValue("name"));
}
} catch (SolrServerException ex) {
throw new RuntimeException("Unable to fetch documents from Solr server", ex);
}
}
示例14: doQuery
import org.apache.solr.client.solrj.response.QueryResponse; //導入方法依賴的package包/類
void doQuery(String expectedDocs, String... queryParams) throws Exception {
List<String> strs = StrUtils.splitSmart(expectedDocs, ",", true);
Map<String, Object> expectedIds = new HashMap<>();
for (int i=0; i<strs.size(); i+=2) {
String id = strs.get(i);
String vS = strs.get(i+1);
Long v = Long.valueOf(vS);
expectedIds.put(id,v);
}
QueryResponse rsp = cloudClient.query(params(queryParams));
Map<String, Object> obtainedIds = new HashMap<>();
for (SolrDocument doc : rsp.getResults()) {
obtainedIds.put((String) doc.get("id"), doc.get(vfield));
}
assertEquals(expectedIds, obtainedIds);
}
示例15: testSimpleAgent
import org.apache.solr.client.solrj.response.QueryResponse; //導入方法依賴的package包/類
@Test
public void testSimpleAgent() {
assertEquals(0, this.commitAndGetSolrDocumentCount("*:*"));
HqAgentController.install("1", HQ_URL, QUEUE_DIRECTORY, SPACE_TOKEN, MARKER);
TestAgent testAgent = new TestAgent();
this.waitFor(5, SECONDS);
AgentControllerProvider.shutdown();
assertTrue(testAgent.getEventCount() > 0);
assertEquals(testAgent.getEventCount(), this.commitAndGetSolrDocumentCount("*:*"));
SolrQuery solrQuery = new SolrQuery("*:*");
solrQuery.addSort("global_id", ORDER.asc);
QueryResponse queryResponse = this.querySolr(solrQuery);
int documentCount = 0;
for (SolrDocument eachDocument : queryResponse.getResults()) {
assertEquals(String.valueOf(++documentCount), eachDocument.getFirstValue("global_id"));
assertEquals(MARKER, eachDocument.getFirstValue("marker"));
}
}