Esempio n. 1
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());
 }
Esempio n. 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();
 }
Esempio n. 3
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;
        }
Esempio n. 4
0
        private Comparison<QueryMatch> GenerateComparisonFunction(Sorter sortBy)
        {
            if (sortBy == null)
                return (x, y) => x.Score.CompareTo(y.Score);

            foreach (var sorter in sortBy.Comparers)
            {
                sorter.Init(this);
            }

            return (x, y) => sortBy.Comparers.Select(term => term.Compare(x, y))
                .FirstOrDefault(ret => ret != 0);
        }