@Override public SortSpec getSort(boolean useGlobal) throws ParseException { SortSpec sort = super.getSort(useGlobal); if (sortStr != null && sortStr.length()>0 && sort.getSort()==null) { Sort oldSort = QueryParsing.parseSort(sortStr, getReq().getSchema()); if( oldSort != null ) { sort.sort = oldSort; } } return sort; }
public boolean includesScore() { return includesScore(sort); }
SortSpec sortSpec() throws SyntaxError { if (sortSpec == null) { sortSpec = qParser != null ? qParser.getSort(true) : QueryParsing.parseSortSpec("id asc", request); sortSpec.setOffset(0); } return sortSpec; }
/** * Creates a SolrIndexSearcher.QueryCommand from this * ResponseBuilder. TimeAllowed is left unset. */ public SolrIndexSearcher.QueryCommand getQueryCommand() { SolrIndexSearcher.QueryCommand cmd = new SolrIndexSearcher.QueryCommand(); cmd.setQuery( getQuery() ) .setFilterList( getFilters() ) .setSort( getSortSpec().getSort() ) .setOffset( getSortSpec().getOffset() ) .setLen( getSortSpec().getCount() ) .setFlags( getFieldFlags() ) .setNeedDocSet( isNeedDocSet() ); return cmd; }
if( sortSpec.getSort() == null ) { sortSpec.setSort( new Sort( new SortField[] { new SortField(idField, booster.comparatorSource, false ), new SortField(null, SortField.SCORE, false) SortField[] current = sortSpec.getSort().getSort(); ArrayList<SortField> sorts = new ArrayList<SortField>( current.length + 1 ); sortSpec.setSort( new Sort( sorts.toArray( new SortField[sorts.size()] ) ) );
private SortSpec makeSortSpec () { Sort sort; // add the uri field as a fallback sorting criterion to enforce a consistent // document order if (sortCriteria != null) { sort = makeSortFromCriteria(getEffectiveSortCriteria()); } else { //sort = new Sort (SortField.FIELD_SCORE, new SortField(uriFieldName, Type.STRING)); sort = new Sort (new SortField(idFieldName, Type.LONG)); } return new SortSpec (sort, position, limit); }
sreq.params.set(CommonParams.ROWS, rb.getSortSpec().getOffset() + rb.getSortSpec().getCount()); if ( (rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES)!=0 || rb.getSortSpec().includesScore()) { sreq.params.set(CommonParams.FL, rb.req.getSchema().getUniqueKeyField().getName() + ",score"); } else {
private void mergeIds(ResponseBuilder rb, ShardRequest sreq) { SortSpec ss = rb.getSortSpec(); Sort sort = ss.getSort(); ShardFieldSortedHitQueue queue = new ShardFieldSortedHitQueue(sortFields, ss.getOffset() + ss.getCount()); int resultSize = queue.size() - ss.getOffset(); resultSize = Math.max(0, resultSize); // there may not be any docs in range if (maxScore!=null) responseDocs.setMaxScore(maxScore); responseDocs.setNumFound(numFound); responseDocs.setStart(ss.getOffset());
sort = QueryParsing.parseSort(sortStr, req.getSchema()); return new SortSpec( sort, start, rows );
private void addSortParam(ModifiableSolrParams params, SortSpec sortSpec) { for (SortField sortField : sortSpec.getSort().getSort()) { String dir = sortField.getReverse() ? "desc" : "asc"; String field = sortField.getField(); if (field != null) { params.add("sort", sortField.getField() + ' ' + dir); } // FIXME Solr controls sorting missing first/last with a *schema* setting, // but we insist on runtime control. We should raise an error here // if the schema is not in line with the runtime setting, since otherwise // an incorrect ordering will be the result. And provide some kind of // "recover from the error" setting? Where? } }
CloudQueryRequest req = new CloudQueryRequest(xqueryComponent.getCore(), params, new SortSpec(Sort.RELEVANCE, 1));
SolrIndexSearcher.QueryCommand queryCommand(final Triple pattern, final SortSpec sortSpec) throws SyntaxError { final SolrIndexSearcher.QueryCommand cmd = new SolrIndexSearcher.QueryCommand(); cmd.setQuery(new MatchAllDocsQuery()); cmd.setSort(sortSpec.getSort()); cmd.setLen(queryFetchSize); cmd.setFlags(cmd.getFlags() | SolrIndexSearcher.GET_DOCSET);
private MLTResult expandQueryAndReExecute(SolrQueryResponse rsp, SolrParams params, int maxDocumentsToMatch, int flags, String q, Query seedQuery, SortSpec sortSpec, List<Query> targetFqFilters, List<Query> mltFqFilters, SolrIndexSearcher searcher, UnsupervisedFeedbackHelper uff, int start, int rows) throws IOException, SyntaxError { boolean includeMatch = params.getBool(UnsupervisedFeedbackParams.MATCH_INCLUDE, true); int matchOffset = params.getInt(UnsupervisedFeedbackParams.MATCH_OFFSET, 0); // Find the base match DocList match = searcher.getDocList(seedQuery, targetFqFilters, null, matchOffset, maxDocumentsToMatch, flags); // only get the first one... if(match.matches() == 0){ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, String.format("Unsupervised feedback handler was unable to find any documents matching the seed query: '%s'.", q)); } if (includeMatch) { rsp.add("match", match); } // This is an iterator, but we only handle the first match DocIterator iterator = match.iterator(); MLTResult mltResult = null; if (iterator.hasNext()) { // do a MoreLikeThis query for each document in results mltResult = uff.expandQueryAndReExecute(iterator, seedQuery, start, rows, mltFqFilters, flags, sortSpec.getSort()); } return mltResult; }
private MLTResult getMoreLikeTheseFromQuery(SolrQueryResponse rsp, SolrParams params, int flags, String q, Query query, SortSpec sortSpec, List<Query> targetFqFilters, List<Query> mltFqFilters, SolrIndexSearcher searcher, MoreLikeThisHelper mlt, int start, int rows) throws IOException, SyntaxError { boolean includeMatch = params.getBool(MoreLikeThisParams.MATCH_INCLUDE, true); int matchOffset = params.getInt(MoreLikeThisParams.MATCH_OFFSET, 0); // Find the base match DocList match = searcher.getDocList(query, targetFqFilters, null, matchOffset, 10000, flags); // only get the first one... if(match.matches() == 0){ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, String.format("MoreLikeThis was unable to find any documents matching the query: '%s'.", q)); } if (includeMatch) { rsp.add("match", match); } // This is an iterator, but we only handle the first match DocIterator iterator = match.iterator(); if (iterator.hasNext()) { // do a MoreLikeThis query for each document in results return mlt.getMoreLikeTheseFromDocs(iterator, start, rows, mltFqFilters, flags, sortSpec.getSort()); } return null; }
Sort sort = rb.getSortSpec().getSort(); SortField[] sortFields = sort==null ? new SortField[]{SortField.FIELD_SCORE} : sort.getSort(); NamedList sortVals = new NamedList(); // order is important for the sort fields
mltResult = mlt.getMoreLikeThisFromContentSteam(reader, start, rows, mltFqFilters, flags, sortSpec.getSort()); } else if (q != null) {