當前位置: 首頁>>代碼示例>>Java>>正文


Java QueryResponse.getResults方法代碼示例

本文整理匯總了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));
		}
	}
 
開發者ID:dimensoft,項目名稱:improved-journey,代碼行數:26,代碼來源:SolrCloudSolrJSearcher.java

示例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;
}
 
開發者ID:apache,項目名稱:metron,代碼行數:18,代碼來源:SolrComponent.java

示例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));
		}
	}
 
開發者ID:dimensoft,項目名稱:improved-journey,代碼行數:19,代碼來源:SolrJSearcher.java

示例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();
}
 
開發者ID:intranda,項目名稱:goobi-viewer-connector,代碼行數:33,代碼來源:SolrSearchIndex.java

示例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();
}
 
開發者ID:intranda,項目名稱:goobi-viewer-connector,代碼行數:29,代碼來源:SolrSearchIndex.java

示例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;
}
 
開發者ID:jenkin2016,項目名稱:solr-sql,代碼行數:23,代碼來源:SolrTable.java

示例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;
}
 
開發者ID:detnavillus,項目名稱:multifield_suggester_code,代碼行數:19,代碼來源:TestSuggestCollectionBuilder.java

示例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();
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:19,代碼來源:MCROAISolrSearcher.java

示例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();
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:25,代碼來源:MCROAISolrSearcher.java

示例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));
    }
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:25,代碼來源:MCRRestAPIClassifications.java

示例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++;
            }
        }
    }
}
 
開發者ID:saschaszott,項目名稱:suma-tech,代碼行數:30,代碼來源:SolrSearcher.java

示例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));
}
 
開發者ID:europeana,項目名稱:search,代碼行數:26,代碼來源:TestDocumentObjectBinder.java

示例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);
  }
}
 
開發者ID:apache,項目名稱:apex-malhar,代碼行數:20,代碼來源:AbstractSolrInputOperator.java

示例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);
  }
 
開發者ID:europeana,項目名稱:search,代碼行數:20,代碼來源:TestDistribDocBasedVersion.java

示例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"));
    }
}
 
開發者ID:Indoqa,項目名稱:logspace,代碼行數:24,代碼來源:SimpleIntegrationTest.java


注:本文中的org.apache.solr.client.solrj.response.QueryResponse.getResults方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。