@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> termSuggest(String query, Integer rows, String sort, String customFq) { if (StringUtils.isBlank(query)) { return new HashSet<>(); } boolean isId = this.isId(query); Map<String, String> options = this.getStaticSolrParams(); if (!isId) { options.putAll(this.getStaticFieldSolrParams()); } Set<OntologyTerm> result = new LinkedHashSet<OntologyTerm>(); for (SolrDocument doc : this.search(produceDynamicSolrParams(query, rows, sort, customFq, isId), options)) { 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; }