List of usage examples for org.apache.solr.common.params CommonParams ROWS
String ROWS
To view the source code for org.apache.solr.common.params CommonParams ROWS.
Click Source Link
From source file:org.phenotips.mendelianSearch.phenotype.DefaultPhenotypeScorer.java
License:Open Source License
/** * Return all terms in the vocabulary./*from w w w. jav a 2s.co m*/ * * @param vocabulary the vocabulary to query * @return a Collection of all VocabularyTerms in the vocabulary */ private Collection<VocabularyTerm> queryAllTerms(Vocabulary vocabulary) { Map<String, String> queryAll = new HashMap<String, String>(); queryAll.put(ID_STRING, "*"); Map<String, String> queryAllParams = new HashMap<String, String>(); queryAllParams.put(CommonParams.ROWS, String.valueOf(vocabulary.size())); Collection<VocabularyTerm> results = vocabulary.search(queryAll, queryAllParams); this.logger.info(String.format(" ... found %d entries.", results.size())); return results; }
From source file:org.phenotips.ontology.internal.GeneNomenclature.java
License:Open Source License
@Override public Set<OntologyTerm> search(Map<String, ?> fieldValues, Map<String, String> queryOptions) { try {/*from ww w . j av a 2 s.co m*/ HttpGet method = new HttpGet( SEARCH_SERVICE_URL + URLEncoder.encode(generateQuery(fieldValues), Consts.UTF_8.name())); method.setHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.getMimeType()); try (CloseableHttpResponse httpResponse = this.client.execute(method)) { String response = IOUtils.toString(httpResponse.getEntity().getContent(), Consts.UTF_8); JSONObject responseJSON = (JSONObject) JSONSerializer.toJSON(response); JSONArray docs = responseJSON.getJSONObject(RESPONSE_KEY).getJSONArray(DATA_KEY); if (docs.size() >= 1) { Set<OntologyTerm> result = new LinkedHashSet<>(); // The remote service doesn't offer any query control, manually select the right range int start = 0; if (queryOptions.containsKey(CommonParams.START) && StringUtils.isNumeric(queryOptions.get(CommonParams.START))) { start = Math.max(0, Integer.parseInt(queryOptions.get(CommonParams.START))); } int end = docs.size(); if (queryOptions.containsKey(CommonParams.ROWS) && StringUtils.isNumeric(queryOptions.get(CommonParams.ROWS))) { end = Math.min(end, start + Integer.parseInt(queryOptions.get(CommonParams.ROWS))); } for (int i = start; i < end; ++i) { result.add(new JSONOntologyTerm(docs.getJSONObject(i), this)); } return result; // This is too slow, for the moment only return summaries // return getTerms(ids); } } catch (IOException ex) { this.logger.warn("Failed to search gene names: {}", ex.getMessage()); } } catch (UnsupportedEncodingException ex) { // This will not happen, UTF-8 is always available } return Collections.emptySet(); }
From source file:org.phenotips.ontology.internal.solr.AbstractSolrOntologyService.java
License:Open Source License
/** * Get the number of entries that match a specific Lucene query. * * @param query a valid the Lucene query as string * @return the number of entries matching the query */// w w w. j a v a 2 s. co m protected long count(String query) { ModifiableSolrParams params = new ModifiableSolrParams(); params.set(CommonParams.Q, query); params.set(CommonParams.START, "0"); params.set(CommonParams.ROWS, "0"); SolrDocumentList results; try { results = this.externalServicesAccess.getServer().query(params).getResults(); return results.getNumFound(); } catch (Exception ex) { this.logger.error("Failed to count ontology terms: {}", ex.getMessage(), ex); return 0; } }
From source file:org.phenotips.ontology.internal.solr.EthnicityOntology.java
License:Open Source License
/** * @param stringSearch part of full ethnicity name * @return set of strings that are full ethnicity names that match the partial string */// w w w. java 2s . c o m public Set<OntologyTerm> getMatchingEthnicities(String stringSearch) { Map<String, String> searchMap = new HashMap<String, String>(); searchMap.put("nameGram", stringSearch); // Order by population size: searchMap.put("_val_", "popsize"); Map<String, String> optionsMap = new HashMap<String, String>(); optionsMap.put(CommonParams.ROWS, "10"); return search(searchMap, optionsMap); }
From source file:org.phenotips.ontology.internal.solr.SolrQueryUtils.java
License:Open Source License
/** * Adds extra parameters to a Solr query for better term searches, including custom options. More specifically, adds * parameters for requesting the score to be included in the results, for requesting a spellcheck result, and sets * the {@code start} and {@code rows} parameters when missing. * * @param originalParams the original Solr parameters to enhance * @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 enhanced parameters/*from www .ja v a2 s.c om*/ */ public static SolrParams enhanceParams(SolrParams originalParams, Map<String, String> queryOptions) { if (originalParams == null) { return null; } ModifiableSolrParams newParams = new ModifiableSolrParams(); newParams.set(CommonParams.START, "0"); newParams.set(CommonParams.ROWS, "1000"); newParams.set(CommonParams.FL, "* score"); if (queryOptions != null) { for (Map.Entry<String, String> item : queryOptions.entrySet()) { newParams.set(item.getKey(), item.getValue()); } } for (Map.Entry<String, Object> item : originalParams.toNamedList()) { if (item.getValue() != null && item.getValue() instanceof String[]) { newParams.set(item.getKey(), (String[]) item.getValue()); } else { newParams.set(item.getKey(), String.valueOf(item.getValue())); } } newParams.set("spellcheck", Boolean.toString(true)); newParams.set(SpellingParams.SPELLCHECK_COLLATE, Boolean.toString(true)); return newParams; }
From source file:org.phenotips.ontology.internal.solr.SolrQueryUtilsTest.java
License:Open Source License
@Test public void testEnhanceParamsDefaultValues() { ModifiableSolrParams input = new ModifiableSolrParams(); SolrParams output = SolrQueryUtils.enhanceParams(input); Assert.assertNull(output.get(CommonParams.Q)); Assert.assertEquals("* score", output.get(CommonParams.FL)); Assert.assertEquals(true, output.getBool(SpellingParams.SPELLCHECK_COLLATE)); Assert.assertEquals(0, (int) output.getInt(CommonParams.START)); Assert.assertTrue(output.getInt(CommonParams.ROWS) > 100); }
From source file:org.phenotips.ontology.internal.solr.SolrQueryUtilsTest.java
License:Open Source License
@Test public void testEnhanceParamsDoesntReplaceExistingValues() { ModifiableSolrParams input = new ModifiableSolrParams(); input.set(CommonParams.Q, "field:value"); input.set(CommonParams.FL, "id"); input.set(CommonParams.START, 30);/*w ww.j a v a2 s . com*/ input.set(CommonParams.ROWS, 10); SolrParams output = SolrQueryUtils.enhanceParams(input); Assert.assertEquals("field:value", output.get(CommonParams.Q)); Assert.assertEquals("id", output.get(CommonParams.FL)); Assert.assertEquals(true, output.getBool(SpellingParams.SPELLCHECK_COLLATE)); Assert.assertEquals(30, (int) output.getInt(CommonParams.START)); Assert.assertEquals(10, (int) output.getInt(CommonParams.ROWS)); }
From source file:org.phenotips.solr.OmimScriptService.java
License:Open Source License
/** * Prepare the map of parameters that can be passed to a Solr query, in order to get a list of diseases matching the * selected positive and negative phenotypes. * * @param phenotypes the list of already selected phenotypes * @param nphenotypes phenotypes that are not observed in the patient * @return the computed Solr query parameters *//*from w w w . j a v a 2 s . c o m*/ private MapSolrParams prepareParams(Collection<String> phenotypes, Collection<String> nphenotypes) { Map<String, String> params = new HashMap<String, String>(); String q = "symptom:" + StringUtils.join(phenotypes, " symptom:"); if (nphenotypes.size() > 0) { q += " not_symptom:" + StringUtils.join(nphenotypes, " not_symptom:"); } q += " -nameSort:\\** -nameSort:\\+* -nameSort:\\^*"; params.put(CommonParams.Q, q.replaceAll("HP:", "HP\\\\:")); params.put(CommonParams.ROWS, "100"); params.put(CommonParams.START, "0"); params.put(CommonParams.DEBUG_QUERY, Boolean.toString(true)); params.put(CommonParams.EXPLAIN_STRUCT, Boolean.toString(true)); return new MapSolrParams(params); }
From source file:org.phenotips.vocabulary.internal.GeneNomenclature.java
License:Open Source License
private SolrParams produceDynamicSolrParams(String originalQuery, Integer rows, String sort, String customFilter) {/*from w ww .jav a 2 s .com*/ String escapedQuery = ClientUtils.escapeQueryChars(originalQuery.trim()); ModifiableSolrParams params = new ModifiableSolrParams(); params.add(CommonParams.Q, escapedQuery); params.add(CommonParams.ROWS, rows.toString()); if (StringUtils.isNotBlank(sort)) { params.add(CommonParams.SORT, sort); } params.add(CommonParams.FQ, StringUtils.defaultIfBlank(customFilter, "status:Approved")); return params; }
From source file:org.phenotips.vocabulary.internal.RemoteGeneNomenclature.java
License:Open Source License
@Override public List<VocabularyTerm> search(Map<String, ?> fieldValues, Map<String, String> queryOptions) { try {//from w w w. ja va2s. co m HttpGet method = new HttpGet( this.searchServiceURL + URLEncoder.encode(generateQuery(fieldValues), Consts.UTF_8.name())); method.setHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.getMimeType()); try (CloseableHttpResponse httpResponse = this.client.execute(method)) { String response = IOUtils.toString(httpResponse.getEntity().getContent(), Consts.UTF_8); JSONObject responseJSON = new JSONObject(response); JSONArray docs = responseJSON.getJSONObject(RESPONSE_KEY).getJSONArray(DATA_KEY); if (docs.length() >= 1) { List<VocabularyTerm> result = new LinkedList<>(); // The remote service doesn't offer any query control, manually select the right range int start = 0; if (queryOptions.containsKey(CommonParams.START) && StringUtils.isNumeric(queryOptions.get(CommonParams.START))) { start = Math.max(0, Integer.parseInt(queryOptions.get(CommonParams.START))); } int end = docs.length(); if (queryOptions.containsKey(CommonParams.ROWS) && StringUtils.isNumeric(queryOptions.get(CommonParams.ROWS))) { end = Math.min(end, start + Integer.parseInt(queryOptions.get(CommonParams.ROWS))); } for (int i = start; i < end; ++i) { result.add(new JSONOntologyTerm(docs.getJSONObject(i), this)); } return result; // This is too slow, for the moment only return summaries // return getTerms(ids); } } catch (IOException | JSONException ex) { this.logger.warn("Failed to search gene names: {}", ex.getMessage()); } } catch (UnsupportedEncodingException ex) { // This will not happen, UTF-8 is always available } return Collections.emptyList(); }