protected void doQuery(Query mainQuery, List<Query> filterQueries, Sort sort) throws IOException { uncollapsedDocSet = searcher.getDocList(mainQuery, filterQueries, sort, 0, collapseMaxDocs, flags); }
public DocListAndSet getMoreLikeThis( Reader reader, int start, int rows, List<Query> filters, List<InterestingTerm> terms, int flags ) throws IOException { mltquery = mlt.like(reader); setBoosts(mltquery); if( terms != null ) { fillInterestingTermsFromMLTQuery( mltquery, terms ); } DocListAndSet results = new DocListAndSet(); if (this.needDocSet) { results = searcher.getDocListAndSet(mltquery, filters, null, start, rows, flags); } else { results.docList = searcher.getDocList(mltquery, filters, null, start, rows, flags); } return results; }
public MLTResult getMoreLikeThisFromContentSteam(Reader reader, int start, int rows, List<Query> filters, int flags, Sort lsort) throws IOException, SyntaxError { MLTQuery mltQuery = mlt.like(reader); Query rawMLTQuery = mltQuery.getOrQuery(); if(mltQuery.getMustMatchQuery() != null || mltQuery.getMustNOTMatchQuery() != null){ throw new RuntimeException( String.format("The %s and the %s parameters are not supported for content stream queries", MoreLikeThisParams.FL_MUST_MATCH, MoreLikeThisParams.FL_MUST_NOT_MATCH)); } Query boostedMLTQuery = getBoostedFunctionQuery( rawMLTQuery ); DocListAndSet results = new DocListAndSet(); if (this.needDocSet) { results = searcher.getDocListAndSet( boostedMLTQuery, filters, lsort, start, rows, flags); } else { results.docList = searcher.getDocList( boostedMLTQuery, filters, lsort, start, rows, flags); } return new MLTResult(mltQuery.getMltTerms(), boostedMLTQuery, results); }
private Set<Integer> getDocidsFromQuery(Query query, SolrIndexSearcher searcher, int maxRows) throws SyntaxError, IOException { DocList match = searcher.getDocList(query, null, null, 0, maxRows, 0); // only get the first one... Set<Integer> docsIds = new HashSet<Integer>(); DocIterator iterator = match.iterator(); while (iterator.hasNext()) { docsIds.add(iterator.nextDoc()); } return docsIds; }
public DocListAndSet getMoreLikeThis( int id, int start, int rows, List<Query> filters, List<InterestingTerm> terms, int flags ) throws IOException { Document doc = reader.document(id); mltquery = mlt.like(id); setBoosts(mltquery); if( terms != null ) { fillInterestingTermsFromMLTQuery( mltquery, terms ); } // exclude current document from results BooleanQuery mltQuery = new BooleanQuery(); mltQuery.add(mltquery, BooleanClause.Occur.MUST); mltQuery.add( new TermQuery(new Term(uniqueKeyField.getName(), uniqueKeyField.getType().storedToIndexed(doc.getFieldable(uniqueKeyField.getName())))), BooleanClause.Occur.MUST_NOT); DocListAndSet results = new DocListAndSet(); if (this.needDocSet) { results = searcher.getDocListAndSet(mltQuery, filters, null, start, rows, flags); } else { results.docList = searcher.getDocList(mltQuery, filters, null, start, rows, flags); } return results; }
/** * Executes a basic query in lucene syntax */ public static DocList doSimpleQuery(String sreq, SolrIndexSearcher searcher, IndexSchema schema, int start, int limit) throws IOException { List<String> commands = StrUtils.splitSmart(sreq,';'); String qs = commands.size() >= 1 ? commands.get(0) : ""; Query query = QueryParsing.parseQuery(qs, schema); // If the first non-query, non-filter command is a simple sort on an indexed field, then // we can use the Lucene sort ability. Sort sort = null; if (commands.size() >= 2) { sort = QueryParsing.parseSort(commands.get(1), schema); } DocList results = searcher.getDocList(query,(DocSet)null, sort, start, limit); return results; }
results = searcher.getDocListAndSet(finalUfQuery, filters, lsort, start, rows, flags); } else { results.docList = searcher.getDocList(finalUfQuery, filters, lsort, start, rows, flags);
/** * Returns a random set of documents from the index. Mainly for testing purposes. * * @param req * @param rsp * @throws IOException */ private void handleRandomSearch(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException { SolrIndexSearcher searcher = req.getSearcher(); Query query = new MatchAllDocsQuery(); DocList docList = searcher.getDocList(query, getFilterQueries(req), Sort.RELEVANCE, 0, numberOfCandidateResults, 0); int paramRows = Math.min(req.getParams().getInt("rows", defaultNumberOfResults), docList.size()); if (docList.size() < 1) { rsp.add("Error", "No documents in index"); } else { LinkedList list = new LinkedList(); while (list.size() < paramRows) { DocList auxList = docList.subset((int) (Math.random() * docList.size()), 1); Document doc = null; for (DocIterator it = auxList.iterator(); it.hasNext(); ) { doc = searcher.doc(it.nextDoc()); } if (!list.contains(doc)) { list.add(doc); } } rsp.addResponse(list); } }
results = searcher.getDocListAndSet(finalMLTQuery, filters, lsort, start, rows, flags); } else { results.docList = searcher.getDocList(finalMLTQuery, filters, lsort, start, rows, flags);
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; }
Filter lfilter=null; DocList results = req.getSearcher().getDocList(query, null, sort, req.getStart(), req.getLimit(), flags); rsp.add(null, results); DocList results2 = req.getSearcher().getDocList(query,query,sort,start,limit); test(results2.size()==results.size() && results2.matches()==results.matches()); DocList results3 = req.getSearcher().getDocList(query,query,null,start,limit); test(results3.size()==results.size() && results3.matches()==results.matches());
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; }
time = System.currentTimeMillis(); if (filterQueries != null) { DocList docList = searcher.getDocList(query, filterQueries, Sort.RELEVANCE, 0, numberOfCandidateResults, 0); numberOfResults = docList.size(); docIterator = docList.iterator();
DocList match = searcher.getDocList(query, null, null, matchOffset, 1, flags ); // only get the first one... if( includeMatch ) { rsp.add( "match", match );