List of usage examples for org.apache.solr.common.params CommonParams Q
String Q
To view the source code for org.apache.solr.common.params CommonParams Q.
Click Source Link
From source file:org.opensextant.extractors.xtax.TaxonMatcher.java
License:Apache License
public static List<Taxon> search(SolrServer index, String query) throws SolrServerException { ModifiableSolrParams qp = new ModifiableSolrParams(); qp.set(CommonParams.FL, "id,catalog,taxnode,phrase,tag,name_type"); qp.set(CommonParams.Q, query); return search(index, qp); }
From source file:org.opensextant.solrtexttagger.TaggerTest.java
License:Open Source License
@Test public void testMultipleFilterQueries() throws Exception { baseParams.set("qt", "/tag"); baseParams.set("overlaps", "ALL"); // build up the corpus with some additional fields for filtering purposes deleteByQueryAndGetVersion("*:*", null); int i = 0;/*from w w w . j a va 2 s . co m*/ assertU(adoc("id", "" + i++, "name", N.London.getName(), "type", "city", "country", "UK")); assertU(adoc("id", "" + i++, "name", N.London_Business_School.getName(), "type", "school", "country", "UK")); assertU(adoc("id", "" + i++, "name", N.Boston.getName(), "type", "city", "country", "US")); assertU(adoc("id", "" + i++, "name", N.City_of_London.getName(), "type", "org", "country", "UK")); assertU(commit()); // not calling buildNames so that we can bring along extra attributes for filtering NAMES = Arrays.stream(N.values()).map(N::getName).collect(Collectors.toList()); // phrase that matches everything String doc = "City of London Business School in Boston"; // first do no filtering ModifiableSolrParams p = new ModifiableSolrParams(); p.add(CommonParams.Q, "*:*"); assertTags(reqDoc(doc, p), tt(doc, "City of London", 0, N.City_of_London), tt(doc, "London", 0, N.London), tt(doc, "London Business School", 0, N.London_Business_School), tt(doc, "Boston", 0, N.Boston)); // add a single fq p.add(CommonParams.FQ, "type:city"); assertTags(reqDoc(doc, p), tt(doc, "London", 0, N.London), tt(doc, "Boston", 0, N.Boston)); // add another fq p.add(CommonParams.FQ, "country:US"); assertTags(reqDoc(doc, p), tt(doc, "Boston", 0, N.Boston)); }
From source file:org.phenotips.diagnosis.differentialPhenotypes.PhenotypeSuggestService.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 www. j av a 2s. c o m*/ private SolrQuery prepareParams(Collection<String> phenotypes, Collection<String> nphenotypes) { SolrQuery result = new SolrQuery(); String q = "symptom:" + StringUtils.join(phenotypes, " symptom:"); if (!nphenotypes.isEmpty()) { q += " not_symptom:" + StringUtils.join(nphenotypes, " not_symptom:"); } q += " -nameSort:\\** -nameSort:\\+* -nameSort:\\^*"; result.set(CommonParams.Q, q.replaceAll("HP:", "HP\\\\:")); result.set(CommonParams.ROWS, "100"); result.set(CommonParams.START, "0"); result.set(CommonParams.DEBUG_QUERY, Boolean.toString(true)); result.set(CommonParams.EXPLAIN_STRUCT, Boolean.toString(true)); return result; }
From source file:org.phenotips.ontology.internal.solr.AbstractSolrOntologyService.java
License:Open Source License
@Override public OntologyTerm getTerm(String id) { OntologyTerm result = this.externalServicesAccess.getCache().get(id); if (result == null) { ModifiableSolrParams params = new ModifiableSolrParams(); params.set(CommonParams.Q, ID_FIELD_NAME + ':' + ClientUtils.escapeQueryChars(id)); SolrDocumentList allResults = this.search(params); if (allResults != null && !allResults.isEmpty()) { result = new SolrOntologyTerm(allResults.get(0), this); this.externalServicesAccess.getCache().set(id, result); } else {/*from w w w.j av a2 s .co m*/ this.externalServicesAccess.getCache().set(id, EMPTY_MARKER); } } return (result == EMPTY_MARKER) ? null : result; }
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 *///from w w w . j av 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.SolrQueryUtils.java
License:Open Source License
/** * Convert a Lucene query string into Solr parameters. More specifically, places the input query under the "q" * parameter./*from w w w . j a v a2 s . c o m*/ * * @param query the lucene query string to use * @return the obtained parameters */ public static SolrParams transformQueryToSolrParams(String query) { ModifiableSolrParams result = new ModifiableSolrParams(); result.add(CommonParams.Q, query); return result; }
From source file:org.phenotips.ontology.internal.solr.SolrQueryUtils.java
License:Open Source License
/** * Replaces the original query in the Solr parameters with the suggested spellchecked query. It also fixes the boost * query, if any./*from w w w.ja v a 2 s .co m*/ * * @param originalParams the original Solr parameters to fix * @param suggestedQuery the suggested query * @return new Solr parameters with the query and boost query fixed */ public static SolrParams applySpellcheckSuggestion(SolrParams originalParams, String suggestedQuery) { if (originalParams == null) { return null; } if (StringUtils.isBlank(suggestedQuery)) { return originalParams; } ModifiableSolrParams newParams = new ModifiableSolrParams(originalParams); String newQuery = suggestedQuery; // Check if the last term in the query is a word stub search which, in case the request comes from a // user-triggered search for terms from the UI, is a prefix search for the last typed word Matcher originalStub = WORD_STUB.matcher(newParams.get(CommonParams.Q)); Matcher newStub = WORD_STUB.matcher(suggestedQuery); if (originalStub.find() && newStub.find() && !StringUtils.equals(originalStub.group(2), newStub.group(2))) { // Since word stubs aren't complete words, they may wrongly be "corrected" to a full word that doesn't match // what the user started typing; include both the original stub and the "corrected" stub in the query newQuery += ' ' + originalStub.group() + "^1.5"; // Also fix the boost query String boostQuery = newParams.get(DisMaxParams.BQ); if (StringUtils.isNotEmpty(boostQuery)) { newParams.add(DisMaxParams.BQ, boostQuery.replace(originalStub.group(2), newStub.group(2))); } } // Replace the query newParams.set(CommonParams.Q, newQuery); return newParams; }
From source file:org.phenotips.ontology.internal.solr.SolrQueryUtilsTest.java
License:Open Source License
@Test public void testTransformQueryToSolrParams() { SolrParams output = SolrQueryUtils.transformQueryToSolrParams("field:value"); Assert.assertEquals("field:value", output.get(CommonParams.Q)); }
From source file:org.phenotips.ontology.internal.solr.SolrQueryUtilsTest.java
License:Open Source License
@Test public void testTransformQueryToSolrParamsWithNullValue() { SolrParams output = SolrQueryUtils.transformQueryToSolrParams(null); Assert.assertNull(output.get(CommonParams.Q)); }
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); }