@Override public GroupResponse group(GroupRequest groupRequest) throws InvalidSearchException { try { String groupNames = groupRequest.getGroups().stream().map(Group::getField).collect( Collectors.joining(",")); SolrQuery query = new SolrQuery() .setStart(0) .setRows(0) .setQuery(groupRequest.getQuery()); query.set("collection", getCollections(groupRequest.getIndices())); Optional<String> scoreField = groupRequest.getScoreField(); if (scoreField.isPresent()) { query.set("stats", true); query.set("stats.field", String.format("{!tag=piv1 sum=true}%s", scoreField.get())); } query.set("facet", true); query.set("facet.pivot", String.format("{!stats=piv1}%s", groupNames)); QueryResponse response = client.query(query); return buildGroupResponse(groupRequest, response); } catch (IOException | SolrServerException e) { String msg = e.getMessage(); LOG.error(msg, e); throw new InvalidSearchException(msg, e); } }
@Override public Iterable<Document> getAllLatest(List<GetRequest> getRequests) throws IOException { Map<String, Collection<String>> collectionIdMap = new HashMap<>(); for (GetRequest getRequest : getRequests) { Optional<String> index = SolrUtilities .getIndex(config.getIndexSupplier(), getRequest.getSensorType(), getRequest.getIndex()); if (index.isPresent()) { Collection<String> ids = collectionIdMap.getOrDefault(index.get(), new HashSet<>()); ids.add(getRequest.getGuid()); collectionIdMap.put(index.get(), ids); } else { LOG.debug("Unable to find index for sensorType {}", getRequest.getSensorType()); } } try { List<Document> documents = new ArrayList<>(); for (String collection : collectionIdMap.keySet()) { SolrDocumentList solrDocumentList = client.getById(collectionIdMap.get(collection), new SolrQuery().set("collection", collection)); documents.addAll( solrDocumentList.stream().map(SolrUtilities::toDocument).collect(Collectors.toList())); } return documents; } catch (SolrServerException e) { throw new IOException(e); } } }
boolean done = false; while (!done) { solrQuery.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark); QueryResponse rsp = solrClient.query(METAALERTS_COLLECTION, solrQuery); String nextCursorMark = rsp.getNextCursorMark();
protected SolrQuery buildSearchRequest( SearchRequest searchRequest, String fieldList) throws IOException, SolrServerException { SolrQuery query = new SolrQuery() .setStart(searchRequest.getFrom()) .setRows(searchRequest.getSize()) .setQuery(searchRequest.getQuery()); // handle sort fields for (SortField sortField : searchRequest.getSort()) { query.addSort(sortField.getField(), getSolrSortOrder(sortField.getSortOrder())); } // handle search fields List<String> fields = searchRequest.getFields(); if (fieldList == null) { fieldList = "*"; if (fields != null) { fieldList = StringUtils.join(fields, ","); } } query.set("fl", fieldList); //handle facet fields List<String> facetFields = searchRequest.getFacetFields(); if (facetFields != null) { facetFields.forEach(query::addFacetField); } query.set("collection", getCollections(searchRequest.getIndices())); return query; }
/** Create a new SolrQuery * * @param q query string */ public SolrQuery(String q) { this(); this.set(CommonParams.Q, q); }
public SolrQuery setFacetPrefix( String field, String prefix ) { this.set( "f."+field+"."+FacetParams.FACET_PREFIX, prefix ); return this; }
/** set the facet limit * * @param lim number facet items to return */ public SolrQuery setFacetLimit(int lim) { this.set(FacetParams.FACET_LIMIT, lim); return this; }
/** * Sets the maximum word length above which words will be ignored. * * @param maxwl the maximum word length * @return this */ public SolrQuery setMoreLikeThisMaxWordLen(int maxwl) { this.set(MoreLikeThisParams.MAX_WORD_LEN, maxwl); return this; }
/** * Sets if the query will be boosted by the interesting term relevance. * * @param b set to true to boost the query with the interesting term relevance * @return this */ public SolrQuery setMoreLikeThisBoost(boolean b) { this.set(MoreLikeThisParams.BOOST, b); return this; }
/** * Sets the minimum word length below which words will be ignored. * * @param minwl the minimum word length * @return this */ public SolrQuery setMoreLikeThisMinWordLen(int minwl) { this.set(MoreLikeThisParams.MIN_WORD_LEN, minwl); return this; }
/** * Sets the number of similar documents to return for each result. * * @param count the number of similar documents to return for each result * @return this */ public SolrQuery setMoreLikeThisCount(int count) { this.set(MoreLikeThisParams.DOC_COUNT, count); return this; }
/** * @return this * @see org.apache.solr.common.params.ModifiableSolrParams#set(String, boolean) */ public SolrQuery setParam(String name, boolean value) { this.set(name, value); return this; }
/** * Sets the frequency below which terms will be ignored in the source doc * * @param mintf the minimum term frequency * @return this */ public SolrQuery setMoreLikeThisMinTermFreq(int mintf) { this.set(MoreLikeThisParams.MIN_TERM_FREQ, mintf); return this; }
/** * Sets the frequency at which words will be ignored which do not occur in * at least this many docs. * * @param mindf the minimum document frequency * @return this */ public SolrQuery setMoreLikeThisMinDocFreq(int mindf) { this.set(MoreLikeThisParams.MIN_DOC_FREQ, mindf); return this; }
public void setGetFieldStatistics( String field ) { this.set( StatsParams.STATS, true ); this.add( StatsParams.STATS_FIELD, field ); }
/** Add field(s) for facet computation. * * @param fields Array of field names from the IndexSchema * @return this */ public SolrQuery addFacetField(String ... fields) { add(FacetParams.FACET_FIELD, fields); this.set(FacetParams.FACET, true); return this; }
/** add a faceting query * * @param f facet query */ public SolrQuery addFacetQuery(String f) { this.add(FacetParams.FACET_QUERY, f); this.set(FacetParams.FACET, true); return this; }
private SolrQuery addValueToParam(String name, String value) { String tmp = this.get(name); tmp = join(tmp, value, ","); this.set(name, tmp); return this; }