Beispiel #1
0
        public QueryResults QueryTop(Query query, int take,
            IndexingConventions.ScorerCalc score = null,
            Sorter sortBy = null)
        {
            if (take < 0)
                throw new ArgumentException("Take must be non negative");

            var qr = new QueryResults();
            var heap = new Heap<QueryMatch>(take, GenerateComparisonFunction(sortBy));
            foreach (var match in Query(query, score))
            {
                heap.Enqueue(match);
                qr.TotalResults++;
            }
            qr.Results = new QueryMatch[heap.Count];
            int pos = 0;
            while (heap.Count > 0)
            {
                qr.Results[pos++] = heap.Dequeue();
            }
            return qr;
        }
Beispiel #2
0
 public IEnumerable<QueryMatch> Query(Query query, IndexingConventions.ScorerCalc score = null, Sorter sortby = null)
 {
     query.Initialize(_index, _tx, score ?? new DefaultScorer(_index.Conventions).Score);
     return query.Execute();
 }