@Override public Set<OntologyTerm> search(Map<String, ?> fieldValues) { return search(fieldValues, null); }
/** * Perform a search, falling back on the suggested spellchecked query if the original query fails to return any * results. * * @param params the Solr parameters to use, should contain at least a value for the "q" parameter * @return the list of matching documents, empty if there are no matching terms */ protected SolrDocumentList search(SolrParams params) { return search(params, null); }
@Override public Set<OntologyTerm> search(Map<String, ?> fieldValues, Map<String, String> queryOptions) { Set<OntologyTerm> result = new LinkedHashSet<OntologyTerm>(); for (SolrDocument doc : this .search(SolrQueryUtils.transformQueryToSolrParams(generateLuceneQuery(fieldValues)), queryOptions)) { result.add(new SolrOntologyTerm(doc, this)); } return result; }
@Override public Set<OntologyTerm> getTerms(Collection<String> ids) { Set<OntologyTerm> result = new LinkedHashSet<OntologyTerm>(); StringBuilder query = new StringBuilder("id:("); for (String id : ids) { OntologyTerm cachedTerm = this.externalServicesAccess.getCache().get(id); if (cachedTerm != null) { if (cachedTerm != EMPTY_MARKER) { result.add(cachedTerm); } } else { query.append(ClientUtils.escapeQueryChars(id)); query.append(' '); } } query.append(')'); // There's at least one more term not found in the cache if (query.length() > 5) { for (SolrDocument doc : this.search(SolrQueryUtils.transformQueryToSolrParams(query.toString()))) { result.add(new SolrOntologyTerm(doc, this)); } } return result; }
@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 { this.externalServicesAccess.getCache().set(id, EMPTY_MARKER); } } return (result == EMPTY_MARKER) ? null : result; }