Esempio n. 1
0
        private IEnumerable <DocumentScore> DoScore(IList <DocumentPosting> postings, string field)
        {
            if (postings.Any())
            {
                var scorer = _scorer.CreateScorer(_ix.DocumentCount.DocCount[field], postings.Count);

                foreach (var posting in postings)
                {
                    var score = scorer.Score(posting);

                    yield return(score);
                }
            }
        }
Esempio n. 2
0
        private IEnumerable <DocumentScore> DoScore(IList <DocumentPosting> postings)
        {
            var docHashesFileName = Path.Combine(_directory, string.Format("{0}.{1}", _ix.VersionId, "pk"));

            using (var docHashReader = new DocHashReader(docHashesFileName))
            {
                if (_scorerFactory == null)
                {
                    foreach (var posting in postings)
                    {
                        var docHash = docHashReader.Read(posting.DocumentId);

                        if (!docHash.IsObsolete)
                        {
                            yield return(new DocumentScore(posting.DocumentId, docHash.Hash, 0, _ix));
                        }
                    }
                }
                else
                {
                    if (postings.Any())
                    {
                        var docsWithTerm = postings.Count;

                        var scorer = _scorerFactory.CreateScorer(_documentCount, docsWithTerm);

                        foreach (var posting in postings)
                        {
                            var docHash = docHashReader.Read(posting.DocumentId);

                            if (!docHash.IsObsolete)
                            {
                                var score = scorer.Score(posting);

                                yield return(new DocumentScore(posting.DocumentId, docHash.Hash, score, _ix));
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        private IEnumerable <DocumentScore> GetScoredResult(Term term, IScoringScheme scoringScheme)
        {
            var trie = GetTrie(term.Field);

            if (_ix == null)
            {
                yield break;
            }
            var totalNumOfDocs = _ix.DocCount[term.Field];

            if (trie.ContainsToken(term.Value))
            {
                var termData = GetPostingsFile(term.Field, term.Value);
                var scorer   = scoringScheme.CreateScorer(totalNumOfDocs, termData.Postings.Count);
                foreach (var posting in termData.Postings)
                {
                    var hit = new DocumentScore(posting.Key, posting.Value, totalNumOfDocs);
                    scorer.Score(hit);
                    yield return(hit);
                }
            }
        }
Esempio n. 4
0
        private IEnumerable <DocumentScore> DoScore(IList <DocumentPosting> postings)
        {
            if (_scorerFactory == null)
            {
                foreach (var posting in postings.OrderBy(p => p.DocumentId))
                {
                    var docHash = _docHashReader.Read(posting.DocumentId);

                    if (!docHash.IsObsolete)
                    {
                        yield return(new DocumentScore(posting.DocumentId, docHash.Hash, 0, _ix));
                    }
                }
            }
            else
            {
                if (postings.Any())
                {
                    var docsWithTerm = postings.Count;

                    var scorer = _scorerFactory.CreateScorer(_documentCount, docsWithTerm);

                    foreach (var posting in postings.OrderBy(p => p.DocumentId))
                    {
                        var docHash = _docHashReader.Read(posting.DocumentId);

                        if (!docHash.IsObsolete)
                        {
                            var score = scorer.Score(posting);

                            yield return(new DocumentScore(posting.DocumentId, docHash.Hash, score, _ix));
                        }
                    }
                }
            }
        }