Ejemplo n.º 1
0
        public static IList <DocumentScore> Sum(this IList <DocumentScore> scores)
        {
            var           sum = new List <DocumentScore>();
            DocumentScore tmp = null;

            foreach (var score in scores)
            {
                if (tmp == null)
                {
                    tmp = score;
                    continue;
                }
                if (score.DocumentId == tmp.DocumentId)
                {
                    tmp.Add(score);
                }
                else
                {
                    sum.Add(tmp);
                }
                tmp = score;
            }
            if (tmp != null)
            {
                sum.Add(tmp);
            }
            return(sum);
        }
Ejemplo n.º 2
0
 private ScoredDocument GetDoc(DocumentScore score)
 {
     using (var readSession = (IFullTextReadSession)_sessionFactory.OpenReadSession(score.Ix))
     {
         return(readSession.ReadDocument(score));
     }
 }
Ejemplo n.º 3
0
        private Document GetDoc(DocumentScore score)
        {
            var doc = _docReader.Get(score.DocumentId);

            doc.Fields["__score"] = score.Score.ToString(CultureInfo.InvariantCulture);

            return(doc);
        }
Ejemplo n.º 4
0
        public void Add(DocumentScore score)
        {
            if (!score.DocumentId.Equals(DocumentId))
            {
                throw new ArgumentException("Document IDs differ. Cannot combine.", "score");
            }

            Score = (Score + score.Score);
        }
Ejemplo n.º 5
0
        public ScoredDocument ReadDocument(DocumentScore score)
        {
            var address        = AddressReader.Read(new BlockInfo(score.DocumentId * BlockSize, BlockSize));
            var documentData   = _documentsReader.ReadOverNetwork(address);
            var documentStream = new MemoryStream(documentData);
            var document       = DocumentSerializer.DeserializeDocument(documentStream, address.Length, Version.Compression, KeyIndex);

            document.TableId = score.DocumentId;
            return(new ScoredDocument(document, score.Score));
        }
Ejemplo n.º 6
0
        public static DocumentScore TakeLatestVersion(DocumentScore first, DocumentScore second)
        {
            if (!first.DocHash.Equals(second.DocHash))
            {
                throw new ArgumentException("Document hashes differ. Cannot take latest version.", "score");
            }

            if (first.Ix.VersionId > second.Ix.VersionId)
            {
                return(first);
            }
            return(second);
        }
Ejemplo n.º 7
0
        public Document GetDocFromDisk(DocumentScore doc)
        {
            var fileId = _docIdToFileIndex[doc.DocId];
            Dictionary <int, Dictionary <string, List <string> > > dics;

            if (!_docFiles.TryGetValue(fileId, out dics))
            {
                dics = ReadDocFile(Path.Combine(_scanner.Dir, fileId + ".d"));
                _docFiles.Add(fileId, dics);
            }
            var dic = dics[doc.DocId];
            var d   = Document.FromDictionary(doc.DocId, dic);

            return(d);
        }
Ejemplo n.º 8
0
        public static IList <DocumentScore> Sum(this IList <DocumentScore>[] scores)
        {
            if (scores.Length == 0)
            {
                return(new DocumentScore[0]);
            }

            if (scores.Length == 1)
            {
                return(scores[0].Sum());
            }

            var first = scores[0];

            for (int i = 1; i < scores.Length; i++)
            {
                first = DocumentScore.CombineAnd(first, scores[i]);
            }
            return(first);
        }
Ejemplo n.º 9
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);
                }
            }
        }
Ejemplo n.º 10
0
        public ScoredDocument ReadDocument(DocumentScore score)
        {
            var document = ReadDocument(score.DocumentId);

            return(new ScoredDocument(document, score.Score));
        }
Ejemplo n.º 11
0
        public void Score(DocumentScore doc)
        {
            var tf = Math.Sqrt((int)doc.PostingData);

            doc.Score = tf * _idf;
        }