List of usage examples for org.apache.solr.common SolrDocumentList getMaxScore
public Float getMaxScore()
From source file:org.phenotips.ontology.internal.solr.AbstractSolrOntologyService.java
License:Open Source License
/** * Perform a search, falling back on the suggested spellchecked query if the original query fails to return any * results.//from w ww .j av a 2 s.c o m * * @param params the Solr parameters to use, should contain at least a value for the "q" parameter * @param queryOptions extra options to include in the query; these override the default values, but don't override * values already set in the query * @return the list of matching documents, empty if there are no matching terms */ protected SolrDocumentList search(SolrParams params, Map<String, String> queryOptions) { try { SolrParams enhancedParams = SolrQueryUtils.enhanceParams(params, queryOptions); QueryResponse response = this.externalServicesAccess.getServer().query(enhancedParams); SolrDocumentList results = response.getResults(); if (response.getSpellCheckResponse() != null && !response.getSpellCheckResponse().isCorrectlySpelled() && StringUtils.isNotEmpty(response.getSpellCheckResponse().getCollatedResult())) { enhancedParams = SolrQueryUtils.applySpellcheckSuggestion(enhancedParams, response.getSpellCheckResponse().getCollatedResult()); SolrDocumentList spellcheckResults = this.externalServicesAccess.getServer().query(enhancedParams) .getResults(); if (results.getMaxScore() < spellcheckResults.getMaxScore()) { results = spellcheckResults; } } return results; } catch (Exception ex) { this.logger.error("Failed to search: {}", ex.getMessage(), ex); } return null; }
From source file:org.phenotips.vocabulary.internal.solr.AbstractSolrVocabulary.java
License:Open Source License
/** * Perform a search, falling back on the suggested spellchecked query if the original query fails to return any * results./*from ww w. j a v a2 s. c o m*/ * * @param params the Solr parameters to use, should contain at least a value for the "q" parameter * @param queryOptions extra options to include in the query; these override the default values, but don't override * values already set in the query * @return the list of matching documents, empty if there are no matching terms */ protected SolrDocumentList search(SolrParams params, Map<String, String> queryOptions) { try { SolrParams enhancedParams = SolrQueryUtils.enhanceParams(params, queryOptions); this.logger.debug("Searching [{}] with query [{}]", getCoreName(), enhancedParams); QueryResponse response = this.externalServicesAccess.getSolrConnection().query(enhancedParams); SolrDocumentList results = response.getResults(); if (response.getSpellCheckResponse() != null && !response.getSpellCheckResponse().isCorrectlySpelled() && StringUtils.isNotEmpty(response.getSpellCheckResponse().getCollatedResult())) { enhancedParams = SolrQueryUtils.applySpellcheckSuggestion(enhancedParams, response.getSpellCheckResponse().getCollatedResult()); this.logger.debug("Searching [{}] with spellchecked query [{}]", getCoreName(), enhancedParams); SolrDocumentList spellcheckResults = this.externalServicesAccess.getSolrConnection() .query(enhancedParams).getResults(); if (results.getMaxScore() < spellcheckResults.getMaxScore()) { results = spellcheckResults; } } return results; } catch (Exception ex) { this.logger.error("Failed to search: {}", ex.getMessage(), ex); } return null; }
From source file:solrbook.ch11.solrj.cli.command.SearchCommand.java
License:Apache License
@Override public void mainProcess(Map<String, Object> parameters) throws Exception { try {/*from www . j a v a 2 s .co m*/ /* * SolrQuery ? */ SolrQuery solrQuery = new SolrQuery(queryString); /* * ?? */ solrQuery.setStart(start); solrQuery.setRows(rows); /* * ?????? */ if (StringUtils.isNotEmpty(sortField) && StringUtils.isNotEmpty(sortOrder)) { /* * ????? */ solrQuery.setSort(sortField, Enum.valueOf(org.apache.solr.client.solrj.SolrQuery.ORDER.class, sortOrder)); } /* * ????? */ for (String f : fieldList.split(",")) { if (StringUtils.isNotEmpty(f)) { solrQuery.addField(f.trim()); } } /* * SolrClient ?? */ QueryResponse queryResponse = solrClient.query(solrQuery); /* * ??????? List ? */ List<Map<String, Object>> documentList = new LinkedList<Map<String, Object>>(); /* * ??? */ SolrDocumentList solrDocumentList = queryResponse.getResults(); /* * ??? */ for (SolrDocument solrDocument : solrDocumentList) { /* * ???? Map ? */ Map<String, Object> documentMap = new HashMap<String, Object>(); /* * ??????? */ for (String fieldName : solrDocument.getFieldNames()) { /* * ??? Map ? */ Object fieldValue = solrDocument.getFieldValue(fieldName); documentMap.put(fieldName, fieldValue); } /* * ? Map ? */ documentMap.put("score", solrDocument.getFieldValue("score")); /* * ??? */ documentList.add(documentMap); } /* * ????? */ response.put("QTime", queryResponse.getQTime()); /* * ???? */ response.put("maxScore", solrDocumentList.getMaxScore()); /* * ???? */ response.put("numFound", solrDocumentList.getNumFound()); /* * ???? */ response.put("result", documentList); status = STATUS_SUCCESS; message = SUCCESS_MESSAGE; } catch (Exception e) { /* * ???? */ status = STATUS_ERROR; message = e.getMessage(); } }