protected RetrieveDocument ( Lucene.Net.Documents.Document document, |
||
document | Lucene.Net.Documents.Document | |
fieldsToFetch | ||
score | float | |
return | Raven.Database.Data.IndexQueryResult |
public IEnumerable <IndexQueryResult> Query() { using (IndexStorage.EnsureInvariantCulture()) { AssertQueryDoesNotContainFieldsThatAreNotIndexes(); IndexSearcher indexSearcher; using (parent.GetSearcher(out indexSearcher)) { var luceneQuery = GetLuceneQuery(); foreach (var indexQueryTrigger in indexQueryTriggers) { luceneQuery = indexQueryTrigger.Value.ProcessQuery(parent.name, luceneQuery, indexQuery); } int start = indexQuery.Start; int pageSize = indexQuery.PageSize; int returnedResults = 0; int skippedResultsInCurrentLoop = 0; do { if (skippedResultsInCurrentLoop > 0) { start = start + pageSize; // trying to guesstimate how many results we will need to read from the index // to get enough unique documents to match the page size pageSize = skippedResultsInCurrentLoop * indexQuery.PageSize; skippedResultsInCurrentLoop = 0; } TopDocs search = ExecuteQuery(indexSearcher, luceneQuery, start, pageSize, indexQuery); indexQuery.TotalSize.Value = search.TotalHits; RecordResultsAlreadySeenForDistinctQuery(indexSearcher, search, start); for (int i = start; i < search.TotalHits && (i - start) < pageSize; i++) { Document document = indexSearcher.Doc(search.ScoreDocs[i].doc); IndexQueryResult indexQueryResult = parent.RetrieveDocument(document, fieldsToFetch, search.ScoreDocs[i].score); if (ShouldIncludeInResults(indexQueryResult) == false) { indexQuery.SkippedResults.Value++; skippedResultsInCurrentLoop++; continue; } returnedResults++; yield return(indexQueryResult); if (returnedResults == indexQuery.PageSize) { yield break; } } } while (skippedResultsInCurrentLoop > 0 && returnedResults < indexQuery.PageSize); } } }
public IEnumerable <IndexQueryResult> Query() { AssertQueryDoesNotContainFieldsThatAreNotIndexes(); var indexSearcher = parent.searcher; indexSearcher.GetIndexReader().IncRef(); try { Query luceneQuery = GetLuceneQuery(); int start = indexQuery.Start; int pageSize = indexQuery.PageSize; int returnedResults = 0; int skippedResultsInCurrentLoop = 0; do { if (skippedResultsInCurrentLoop > 0) { start = start + pageSize; // trying to guesstimate how many results we will need to read from the index // to get enough unique documents to match the page size pageSize = skippedResultsInCurrentLoop * indexQuery.PageSize; skippedResultsInCurrentLoop = 0; } TopDocs search = ExecuteQuery(indexSearcher, luceneQuery, start, pageSize, indexQuery); indexQuery.TotalSize.Value = search.totalHits; RecordResultsAlreadySeenForDistinctQuery(indexSearcher, search, start); for (int i = start; i < search.totalHits && (i - start) < pageSize; i++) { Document document = indexSearcher.Doc(search.scoreDocs[i].doc); IndexQueryResult indexQueryResult = parent.RetrieveDocument(document, fieldsToFetch, search.scoreDocs[i].score); if (ShouldIncludeInResults(indexQueryResult) == false) { indexQuery.SkippedResults.Value++; skippedResultsInCurrentLoop++; continue; } returnedResults++; yield return(indexQueryResult); if (returnedResults == indexQuery.PageSize) { yield break; } } } while (skippedResultsInCurrentLoop > 0 && returnedResults < indexQuery.PageSize); } finally { indexSearcher.GetIndexReader().DecRef(); } }