List of usage examples for org.apache.solr.client.solrj SolrQuery set
public ModifiableSolrParams set(String name, String... val)
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 w w w . j a va 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.AbstractOBOSolrOntologyService.java
License:Open Source License
@Override public String getVersion() { QueryResponse response;/*w w w. ja v a2 s.co m*/ SolrQuery query = new SolrQuery(); SolrDocumentList termList; SolrDocument firstDoc; query.setQuery("version:*"); query.set("rows", "1"); try { response = this.externalServicesAccess.getServer().query(query); termList = response.getResults(); if (!termList.isEmpty()) { firstDoc = termList.get(0); return firstDoc.getFieldValue(VERSION_FIELD_NAME).toString(); } } catch (SolrServerException | SolrException ex) { this.logger.warn("Failed to query ontology version: {}", ex.getMessage()); } return null; }
From source file:org.phenotips.ontology.internal.solr.HumanPhenotypeOntology.java
License:Open Source License
@Override public String getVersion() { QueryResponse response;//from w w w . j a va2 s. co m SolrQuery query = new SolrQuery(); SolrDocumentList termList; SolrDocument firstDoc; query.setQuery("version:*"); query.set("rows", "1"); try { response = this.externalServicesAccess.getServer().query(query); termList = response.getResults(); if (!termList.isEmpty()) { firstDoc = termList.get(0); return firstDoc.getFieldValue(VERSION_FIELD_NAME).toString(); } } catch (SolrServerException ex) { this.logger.warn("Failed to query ontology version {}", ex.getMessage()); } return null; }
From source file:org.phenotips.variantstore.db.solr.SolrUtils.java
License:Open Source License
/** * Loop over all the documents returned by the query. This method queries the DB multiple times. Every time we get * data back, we pass it onto a processor, and stop processing data if the processor tells us it's had enough. * * @param server the solr db//from w ww .j a va 2s .c o m * @param q the query * @param uniqueKey the solr uniqueKey field to sort on. Required for solr's Cursor functionality. *@param processor the processor to handle the data. If the function returns true, we stop fetching more data. * @throws IOException * @throws SolrServerException */ static void processAllDocs(SolrClient server, SolrQuery q, String uniqueKey, Function<Collection<SolrDocument>, Boolean> processor) throws IOException, SolrServerException { boolean done = false; String oldCursorMark; String cursorMark = CursorMarkParams.CURSOR_MARK_START; QueryResponse resp; // Cursor functionality requires a sort containing a uniqueKey field tie breaker q.addSort(uniqueKey, SolrQuery.ORDER.desc); while (!done) { oldCursorMark = cursorMark; q.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark); resp = server.query(q); done = processor.apply(resp.getResults()); cursorMark = resp.getNextCursorMark(); done = done || oldCursorMark.equals(cursorMark); } }
From source file:org.phenotips.vocabulary.internal.solr.AbstractCSVSolrVocabulary.java
License:Open Source License
protected VocabularyTerm requestTerm(String queryString, String phraseFields) { QueryResponse response;/*from w ww. jav a 2 s . co m*/ SolrQuery query = new SolrQuery(); SolrDocumentList termList; VocabularyTerm term; query.setQuery(queryString); query.setRows(1); if (phraseFields != null) { query.set(DisMaxParams.PF, phraseFields); } try { response = this.externalServicesAccess.getSolrConnection().query(query); termList = response.getResults(); if (!termList.isEmpty()) { term = new SolrVocabularyTerm(termList.get(0), this); return term; } } catch (SolrServerException | SolrException ex) { this.logger.warn("Failed to query ontology term: {} ", ex.getMessage()); } catch (IOException ex) { this.logger.error("IOException while getting ontology term ", ex); } return null; }
From source file:org.phenotips.vocabulary.internal.solr.AbstractCSVSolrVocabulary.java
License:Open Source License
@Override public String getVersion() { QueryResponse response;/*from www . ja va2 s .c o m*/ SolrQuery query = new SolrQuery(); SolrDocumentList termList; SolrDocument firstDoc; query.setQuery("version:*"); query.set(CommonParams.ROWS, "1"); try { response = this.externalServicesAccess.getSolrConnection().query(query); termList = response.getResults(); if (!termList.isEmpty()) { firstDoc = termList.get(0); return firstDoc.getFieldValue(VERSION_FIELD_NAME).toString(); } } catch (SolrServerException | SolrException ex) { this.logger.warn("Failed to query ontology version: {}", ex.getMessage()); } catch (IOException ex) { this.logger.error("IOException while getting ontology version", ex); } return null; }
From source file:org.phenotips.vocabulary.internal.solr.AbstractOBOSolrVocabulary.java
License:Open Source License
@Override public String getVersion() { QueryResponse response;/*from w w w . ja v a 2 s .c o m*/ SolrQuery query = new SolrQuery(); SolrDocumentList termList; SolrDocument firstDoc; query.setQuery("version:*"); query.set("rows", "1"); try { response = this.externalServicesAccess.getSolrConnection().query(query); termList = response.getResults(); if (!termList.isEmpty()) { firstDoc = termList.get(0); return firstDoc.getFieldValue(VERSION_FIELD_NAME).toString(); } } catch (SolrServerException | SolrException | IOException ex) { this.logger.warn("Failed to query ontology version: {}", ex.getMessage()); } return null; }
From source file:org.phenotips.vocabulary.internal.solr.AbstractOWLSolrVocabulary.java
License:Open Source License
@Override public String getVersion() { final SolrQuery query = new SolrQuery(); query.setQuery("version:*"); query.set(CommonParams.ROWS, "1"); try {/* w w w . ja v a2 s. c o m*/ final QueryResponse response = this.externalServicesAccess.getSolrConnection(getCoreName()) .query(query); final SolrDocumentList termList = response.getResults(); if (!termList.isEmpty()) { final SolrDocument firstDoc = termList.get(0); return firstDoc.getFieldValue(VERSION_FIELD_NAME).toString(); } } catch (SolrServerException | SolrException | IOException ex) { this.logger.warn("Failed to query ontology version: {}", ex.getMessage()); } return null; }
From source file:org.phenotips.vocabulary.internal.solr.FrenchHPOTranslationTest.java
License:Open Source License
@Test public void queriesAreExtendedToIncludeFrenchFieldsWhenLocaleIsFr() { SolrQuery query = new SolrQuery("seizures"); query.set(DisMaxParams.QF, "name"); query.set(DisMaxParams.PF, "name"); this.component.extendQuery(query, this.vocabulary); Assert.assertEquals("name name_fr^60 synonym_fr^45 def_fr^12 ", query.get(DisMaxParams.PF)); Assert.assertEquals("name name_fr^30 synonym_fr^21 def_fr^6 ", query.get(DisMaxParams.QF)); }
From source file:org.phenotips.vocabulary.internal.solr.FrenchHPOTranslationTest.java
License:Open Source License
@Test public void queriesAreExtendedToIncludeFrenchFieldsWhenLocaleIsFrFR() { when(this.localizationContext.getCurrentLocale()).thenReturn(Locale.FRANCE); SolrQuery query = new SolrQuery("seizures"); query.set(DisMaxParams.QF, "name"); query.set(DisMaxParams.PF, "name"); this.component.extendQuery(query, this.vocabulary); Assert.assertEquals("name name_fr^60 synonym_fr^45 def_fr^12 ", query.get(DisMaxParams.PF)); Assert.assertEquals("name name_fr^30 synonym_fr^21 def_fr^6 ", query.get(DisMaxParams.QF)); }