/** * Sets up the sorting criteria. This will support sorting by multiple fields at a time * * @param query * @param searchCriteria */ protected void attachSortClause(SolrQuery query, SearchCriteria searchCriteria, String defaultSort) { shs.attachSortClause(query, searchCriteria, defaultSort); query.addSort("score", SolrQuery.ORDER.desc); }
String item = order1.getKey(); SolrQuery.ORDER order = order1.getOrder() == Order.ASC ? SolrQuery.ORDER.asc : SolrQuery.ORDER.desc; solrQuery.addSort(new SolrQuery.SortClause(item, order));
.setQuery(fullClause) .setFields("*", "[child parentFilter=" + metaalertTypeClause + " limit=999]") .addSort(Constants.GUID,
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; }
/** * Adds a single sort clause to the end of the current sort information. * * @return the modified SolrQuery object, for easy chaining * @since 4.2 */ public SolrQuery addSort(String field, ORDER order) { return addSort(new SortClause(field, order)); }
/** * Replaces the current sort information with a single sort clause * * @return the modified SolrQuery object, for easy chaining * @since 4.2 */ public SolrQuery setSort(SortClause sortClause) { clearSorts(); return addSort(sortClause); }
/** * Adds a single sort clause to the end of the current sort information. * * @return the modified SolrQuery object, for easy chaining * @since 4.2 */ public SolrQuery addSort(String field, ORDER order) { return addSort(new SortClause(field, order)); }
/** * Replaces the current sort information with a single sort clause * * @return the modified SolrQuery object, for easy chaining * @since 4.2 */ public SolrQuery setSort(SortClause sortClause) { clearSorts(); return addSort(sortClause); }
private void addSortField(final SolrQuery solrQuery, String field, ORDER order) { SortClause clause = new SortClause(field, order); solrQuery.addSort(clause); }
/** * Append sorting parameters to {@link SolrQuery} * * @param solrQuery * @param sort */ protected void appendSort(SolrQuery solrQuery, @Nullable Sort sort, @Nullable Class<?> domainType) { if (sort == null) { return; } for (Order order : sort) { solrQuery.addSort(getMappedFieldName(order.getProperty(), domainType), order.isAscending() ? ORDER.asc : ORDER.desc); } }
/** * Updates or adds a single sort field specification to the current sort * information. If the sort field already exist in the sort information map, * its position is unchanged and the sort order is set; if it does not exist, * it is appended at the end with the specified order.. * * @return the modified SolrQuery object, for easy chaining * @since 4.2 */ public SolrQuery addOrUpdateSort(SortClause sortClause) { if (sortClauses != null) { for (int index=0 ; index<sortClauses.size() ; index++) { SortClause existing = sortClauses.get(index); if (existing.getItem().equals(sortClause.getItem())) { sortClauses.set(index, sortClause); serializeSorts(); return this; } } } return addSort(sortClause); }
/** * Updates or adds a single sort field specification to the current sort * information. If the sort field already exist in the sort information map, * its position is unchanged and the sort order is set; if it does not exist, * it is appended at the end with the specified order.. * * @return the modified SolrQuery object, for easy chaining * @since 4.2 */ public SolrQuery addOrUpdateSort(SortClause sortClause) { if (sortClauses != null) { for (int index=0 ; index<sortClauses.size() ; index++) { SortClause existing = sortClauses.get(index); if (existing.getItem().equals(sortClause.getItem())) { sortClauses.set(index, sortClause); serializeSorts(); return this; } } } return addSort(sortClause); }
private SolrQuery addDynamicQueryParameters(String originalQuery, Integer rows, String sort, String customFq, boolean isId, SolrQuery query) { String queryString = originalQuery.trim(); String escapedQuery = ClientUtils.escapeQueryChars(queryString); if (isId) { query.setFilterQueries(new MessageFormat("id:{0}").format(new String[] { escapedQuery })); } query.setQuery(escapedQuery); query.set(SpellingParams.SPELLCHECK_Q, queryString); query.setRows(rows); if (StringUtils.isNotBlank(sort)) { for (String sortItem : sort.split("\\s*,\\s*")) { query.addSort(StringUtils.substringBefore(sortItem, " "), sortItem.endsWith(" desc") || sortItem.startsWith("-") ? ORDER.desc : ORDER.asc); } } return query; }
private SolrQuery addDynamicQueryParameters(String originalQuery, Integer rows, String sort, String customFq, boolean isId, SolrQuery query) { String queryString = originalQuery.trim(); String escapedQuery = ClientUtils.escapeQueryChars(queryString); if (isId) { query.setFilterQueries(new MessageFormat("id:{0}").format(new String[] { escapedQuery })); } query.setQuery(escapedQuery); query.set(SpellingParams.SPELLCHECK_Q, queryString); query.setRows(rows); if (StringUtils.isNotBlank(sort)) { for (String sortItem : sort.split("\\s*,\\s*")) { query.addSort(StringUtils.substringBefore(sortItem, " "), sortItem.endsWith(" desc") || sortItem.startsWith("-") ? ORDER.desc : ORDER.asc); } } return query; }
private SolrQuery addDynamicQueryParameters(String originalQuery, Integer rows, String sort, String customFq, boolean isId, SolrQuery query) { String queryString = originalQuery.trim(); String escapedQuery = ClientUtils.escapeQueryChars(queryString); if (isId) { query.setFilterQueries(StringUtils.defaultIfBlank(customFq, new MessageFormat("id:{0} alt_id:{0}").format(new String[] { escapedQuery }))); } else { query.setFilterQueries(StringUtils.defaultIfBlank(customFq, "term_category:HP\\:0000118")); } query.setQuery(escapedQuery); query.set(SpellingParams.SPELLCHECK_Q, queryString); query.setRows(rows); if (StringUtils.isNotBlank(sort)) { for (String sortItem : sort.split("\\s*,\\s*")) { query.addSort(StringUtils.substringBefore(sortItem, " "), sortItem.endsWith(" desc") || sortItem.startsWith("-") ? ORDER.desc : ORDER.asc); } } return query; }
private SolrQuery addDynamicQueryParameters(String originalQuery, Integer rows, String sort, String customFq, boolean isId, SolrQuery query) { String queryString = originalQuery.trim(); String escapedQuery = ClientUtils.escapeQueryChars(queryString); if (isId) { query.setFilterQueries(StringUtils.defaultIfBlank(customFq, new MessageFormat("id:{0} alt_id:{0}").format(new String[] { escapedQuery }))); } else if (StringUtils.isNotBlank(customFq)) { query.setFilterQueries(customFq); } query.setQuery(escapedQuery); query.set(SpellingParams.SPELLCHECK_Q, queryString); query.setRows(rows); if (StringUtils.isNotBlank(sort)) { for (String sortItem : sort.split("\\s*,\\s*")) { query.addSort(StringUtils.substringBefore(sortItem, " "), sortItem.endsWith(" desc") || sortItem.startsWith("-") ? ORDER.desc : ORDER.asc); } } return query; }
SolrQuery solrQuery = new SolrQuery(); solrQuery.setRows(500); solrQuery.setQuery("*:*"); solrQuery.addSort("id", ORDER.asc); // Pay attention to this line String cursorMark = CursorMarkParams.CURSOR_MARK_START; boolean done = false; while (!done) { solrQuery.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark); QueryResponse rsp = solrClient.query(solrQuery); String nextCursorMark = rsp.getNextCursorMark(); for (SolrDocument d : rsp.getResults()) { ... } if (cursorMark.equals(nextCursorMark)) { done = true; } cursorMark = nextCursorMark; }
SolrClient solr = new HttpSolrClient.Builder("<url>").build(); SolrQuery query = new SolrQuery(); query.setQuery("collector:" + input); query.addFilterQuery("(doc_type:" + entity + ")"); query.addSort("lastUpdatedAt", ORDER.desc); query.setFacet(true); query.setStart(pagenumber); query.setRows(pagesize); QueryResponse response = solr.query(query);
/** * Tag slower documents and add them to the shrank core */ private void tagAndAddSlowThothDocuments() throws IOException, SolrServerException { // Query to return top MAX_NUMBER_SLOW_THOTH_DOCS slower thoth documents QueryResponse qr = realTimeServer.query( new SolrQuery() .setQuery(createThothDocsAggregationQuery()) .addSort(QTIME, SolrQuery.ORDER.desc) .setRows(MAX_NUMBER_SLOW_THOTH_DOCS) ); for (SolrDocument solrDocument: qr.getResults()){ SolrInputDocument si = ClientUtils.toSolrInputDocument(solrDocument); // Remove old ID and version si.removeField(ID); si.removeField("_version_"); // Tag document as slow si.addField(SLOW_QUERY_DOCUMENT, true); LOG.debug("Adding slow query document for server " + serverDetail.getName()); shrankServer.add(si); } }