Пример #1
0
        public void Write(DocumentTableRow document, IWriteSession session)
        {
            var analyzedTerms = _analyzer.AnalyzeDocument(document);

            foreach (var term in analyzedTerms)
            {
                _treeBuilder.Add(term.Field, term.Value, term);
            }

            session.Write(document);

            Log.DebugFormat("analyzed doc ID {0}", document.TableId);
        }
Пример #2
0
        private BinaryTree ReadTree(BitStream bs, BinaryTree.Node root)
        {
            var count = (ushort)bs.ReadBits(16);

            if (count > 285)
            {
                throw new Exception("Unexpected number of symbols");
            }

            var builder = new TreeBuilder()
            {
                Value = (ushort)(count - 1), //used as the root value when no nodes were added
            };

            while (count > 0)
            {
                var n       = ReadNode(bs, root);
                var bits    = (byte)(n.Value & 0x1F);
                var symbols = (ushort)((n.Value >> 5) + 1);

                if (symbols > count)
                {
                    throw new Exception("Unexpected number of symbols in tree");
                }

                if (bits == 0)
                {
                    count -= symbols;
                }
                else
                {
                    while (symbols > 0)
                    {
                        builder.Add(bits, --count);
                        --symbols;
                    }
                }
            }

            return(builder.Build());
        }