当前位置: 首页>>代码示例>>Java>>正文


Java QueryResponse类代码示例

本文整理汇总了Java中org.apache.solr.client.solrj.response.QueryResponse的典型用法代码示例。如果您正苦于以下问题:Java QueryResponse类的具体用法?Java QueryResponse怎么用?Java QueryResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


QueryResponse类属于org.apache.solr.client.solrj.response包,在下文中一共展示了QueryResponse类的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: fetchExistingOrCreateNewSolrDoc

import org.apache.solr.client.solrj.response.QueryResponse; //导入依赖的package包/类
private SolrInputDocument fetchExistingOrCreateNewSolrDoc(String id) throws SolrServerException, IOException {
  Map<String, String> p = new HashMap<String, String>();
  p.put("q", PHRASE + ":\"" + ClientUtils.escapeQueryChars(id) + "\"");
  
  SolrParams params = new MapSolrParams(p);
  
  QueryResponse res = solrAC.query(params);
  
  if (res.getResults().size() == 0) {
    return new SolrInputDocument();
  } else if (res.getResults().size() == 1) {
    SolrDocument doc = res.getResults().get(0);
    SolrInputDocument tmp = new SolrInputDocument();
    
    for (String fieldName : doc.getFieldNames()) {
      tmp.addField(fieldName, doc.getFieldValue(fieldName));
    }
    return tmp;
  } else {
    throw new IllegalStateException("Query with params : " + p + " returned more than 1 hit!");
  }
}
 
开发者ID:sematext,项目名称:solr-autocomplete,代码行数:23,代码来源:AutocompleteUpdateRequestProcessor.java

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: getSets

import org.apache.solr.client.solrj.response.QueryResponse; //导入依赖的package包/类
/**
 * Creates a list with all available values for the given field (minus any blacklisted values).
 * 
 * @return
 * @throws SolrServerException
 * @should return all values
 */
public List<String> getSets(String field) throws SolrServerException {
    List<String> ret = new ArrayList<>();

    SolrQuery query = new SolrQuery();
    query.setQuery(field + ":* " + DataManager.getInstance().getConfiguration().getCollectionBlacklistFilterSuffix());
    query.setStart(0);
    query.setRows(0);
    query.addFacetField(field);
    logger.trace("Set query: {}", query.getQuery());
    QueryResponse resp = server.query(query);

    FacetField facetField = resp.getFacetField(field);
    if (facetField != null) {
        for (Count count : facetField.getValues()) {
            if (count.getCount() == 0) {
                continue;
            }
            ret.add(count.getName());
        }
    }

    Collections.sort(ret);
    logger.trace("{} terms found for {}", ret.size(), field);
    return ret;
}
 
开发者ID:intranda,项目名称:goobi-viewer-connector,代码行数:33,代码来源:SolrSearchIndex.java

示例8: getTotalHitNumber

import org.apache.solr.client.solrj.response.QueryResponse; //导入依赖的package包/类
/**
 * 
 * @param params
 * @param urnOnly
 * @param querySuffix
 * @return size of search
 * @throws IOException
 * @throws SolrServerException
 */
public long getTotalHitNumber(Map<String, String> params, boolean urnOnly, String querySuffix) throws IOException, SolrServerException {
    StringBuilder sbQuery = new StringBuilder(buildQueryString(params.get("from"), params.get("until"), params.get("set"), params.get(
            "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(0);
    solrQuery.setRows(0);
    solrQuery.addSort(SolrConstants.DATECREATED, ORDER.asc);
    QueryResponse resp = server.query(solrQuery);

    long num = resp.getResults().getNumFound();
    logger.debug("Total hits: {}", num);
    return num;
}
 
开发者ID:intranda,项目名称:goobi-viewer-connector,代码行数:28,代码来源:SolrSearchIndex.java

示例9: 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

示例10: query

import org.apache.solr.client.solrj.response.QueryResponse; //导入依赖的package包/类
public QueryResponse query(ModifiableSolrParams params) throws SolrServerException
{
   	try
   	{
	    QueryResponse response = server.query(params);
	    if(response.getStatus() != 0)
	    {
	    	solrTracker.setSolrActive(false);
	    }

	    return response;
	}
	catch(SolrServerException e)
	{
		solrTracker.setSolrActive(false);
		throw e;
	}
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:19,代码来源:SOLRAdminClient.java

示例11: testRuntimeLib

import org.apache.solr.client.solrj.response.QueryResponse; //导入依赖的package包/类
@Test
public void testRuntimeLib() throws SolrServerException, IOException {
    SearchServer server = testSearchServer.getSearchServer();

    SolrClient client = (SolrClient) server.getBackend();

    SolrInputDocument document = new SolrInputDocument();
    document.setField("_id_", "1");
    document.setField("_type_", "doc");
    document.setField("dynamic_multi_facet_string_f1", "test");
    document.setField("dynamic_multi_facet_string_f2", "hello");

    client.add(document);
    client.commit();

    SolrQuery query = new SolrQuery("t");
    query.setRequestHandler("/suggester");
    query.set("suggestion.df", "facets");
    query.set("suggestion.field", "dynamic_multi_facet_string_f1");

    QueryResponse response = client.query(query);

    assertEquals(1, ((HashMap) response.getResponse().get("suggestions")).get("suggestion_count"));
}
 
开发者ID:RBMHTechnology,项目名称:vind,代码行数:25,代码来源:TestServerTest.java

示例12: getVersionAndInstallIfNecessary

import org.apache.solr.client.solrj.response.QueryResponse; //导入依赖的package包/类
public Long getVersionAndInstallIfNecessary(String dependency) {

        try {
            SolrQuery query = new SolrQuery("blobName:"+Utils.toBlobName(dependency));
            query.setSort("version", SolrQuery.ORDER.desc);
            QueryResponse response = client.query(".system",query);

            if(response.getResults().getNumFound() > 0) { //should could look for updates here as well?

                return Long.valueOf(response.getResults().get(0).get("version").toString());
            } else {
                Path configDirectory = Files.createTempDirectory(dependency);

                Path jarFile = Utils.downloadToTempDir(configDirectory, repositories, dependency);

                return uploadRuntimeLib(dependency, jarFile);
            }

        } catch (SolrServerException | IOException e) {
            logger.warn("Cannot load runtime dependeny " + dependency + ". This may cause runtime issues.");
            return -1L;
        }
    }
 
开发者ID:RBMHTechnology,项目名称:vind,代码行数:24,代码来源:CollectionManagementService.java

示例13: execute

import org.apache.solr.client.solrj.response.QueryResponse; //导入依赖的package包/类
@Override
public SuggestionResult execute(ExecutableSuggestionSearch search, DocumentFactory assets,DocumentFactory childFactory) {
    SolrQuery query = buildSolrQuery(search, assets, childFactory);

    try {
        log.debug(">>> query({})", query.toString());
        QueryResponse response = solrClient.query(query);
        if(response!=null){
            return SolrUtils.Result.buildSuggestionResult(response, assets, childFactory, search.getSearchContext());
        }else {
            log.error("Null result from SolrClient");
            throw new SolrServerException("Null result from SolrClient");
        }

    } catch (SolrServerException | IOException e) {
        log.error("Cannot execute suggestion query");
        throw new SearchServerException("Cannot execute suggestion query", e);
    }
}
 
开发者ID:RBMHTechnology,项目名称:vind,代码行数:20,代码来源:SolrSearchServer.java

示例14: findCurrentDataRepository

import org.apache.solr.client.solrj.response.QueryResponse; //导入依赖的package包/类
/**
 * 
 * @param pi
 * @return The name of the data repository currently used for the record with the given PI; "?" if the record is indexed, but not in a repository;
 *         null if the record is not in the index
 * @throws SolrServerException
 * @should find correct data repository for record
 */
public String findCurrentDataRepository(String pi) throws SolrServerException {
    SolrQuery solrQuery = new SolrQuery(SolrConstants.PI + ":" + pi);
    solrQuery.setRows(1);
    solrQuery.setFields(SolrConstants.DATAREPOSITORY);
    QueryResponse resp = server.query(solrQuery);

    if (!resp.getResults().isEmpty()) {
        if (resp.getResults().get(0).getFieldValue(SolrConstants.DATAREPOSITORY) != null) {
            return (String) resp.getResults().get(0).getFieldValue(SolrConstants.DATAREPOSITORY);
        }
        return "?";
    }

    return null;
}
 
开发者ID:intranda,项目名称:goobi-viewer-indexer,代码行数:24,代码来源:SolrHelper.java

示例15: fromQueryResponse

import org.apache.solr.client.solrj.response.QueryResponse; //导入依赖的package包/类
private static <T> SearchResult<T> fromQueryResponse(QueryResponse solrQueryResponse, Function<Group, T> resultMapper) {
    final List<Group> results = solrQueryResponse.getGroupResponse().getValues().get(0).getValues();

    int numFound = solrQueryResponse.getGroupResponse().getValues().get(0).getNGroups();
    //TODO paging
    int start = 0;

    final SearchResult<T> searchResult = new SearchResult<>(numFound, start,
            results.stream().map(resultMapper).collect(Collectors.toList()));

    //TODO
    // if (results.getMaxScore() != null) {
    //    searchResult.setMaxScore(results.getMaxScore());
    //}
    if(solrQueryResponse.getHighlighting() != null){
        searchResult.getParams().put("highlighting", solrQueryResponse.getHighlighting());
    }
    if(solrQueryResponse.getHeader() != null){
        searchResult.getParams().put("header", solrQueryResponse.getHeader().asMap(Integer.MAX_VALUE));
    }
    //TODO: maybe we want fact data
    
    return searchResult;
}
 
开发者ID:redlink-gmbh,项目名称:smarti,代码行数:25,代码来源:ConversationSearchService.java


注:本文中的org.apache.solr.client.solrj.response.QueryResponse类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。