Example #1
0
        public static byte[] Serialize(this DocumentTableRow document, Compression compression)
        {
            using (var stream = new MemoryStream())
            {
                document.Fields.Serialize(compression, stream);

                return(stream.ToArray());
            }
        }
Example #2
0
        public IList <AnalyzedTerm> AnalyzeDocument(DocumentTableRow document)
        {
            var analyzedTerms = new List <AnalyzedTerm>();

            foreach (var field in document.Fields.Values)
            {
                if (field.Analyze && field.Index)
                {
                    var words      = Analyze(field.Value);
                    var wordMatrix = new Dictionary <string, IList <int> >();

                    for (var index = 0; index < words.Count; index++)
                    {
                        var         word = words[index];
                        IList <int> positions;
                        if (wordMatrix.TryGetValue(word, out positions))
                        {
                            positions.Add(index);
                        }
                        else
                        {
                            wordMatrix.Add(word, new List <int> {
                                index
                            });
                        }

                        //Log.DebugFormat("found term {0} at pos {1}", word, index);
                    }

                    foreach (var wordInfo in wordMatrix)
                    {
                        var postings = new List <int>(wordInfo.Value.Count);

                        foreach (var position in wordInfo.Value)
                        {
                            postings.Add(position);
                        }

                        analyzedTerms.Add(
                            new AnalyzedTerm(document.TableId, field.Key, wordInfo.Key, postings));
                    }
                }
                else if (field.Index)
                {
                    var postings = new int[] { 0 };

                    analyzedTerms.Add(
                        new AnalyzedTerm(document.TableId, field.Key, field.Value, postings));
                }
            }
            return(analyzedTerms);
        }