Example #1
0
        internal FullTextIndex(
            IndexOptions indexOptions,
            ConfiguredObjectTokenizationOptions <TKey> itemTokenizationOptions,
            IIndexNodeFactory indexNodeFactory,
            IQueryParser queryParser,
            IIndexScorerFactory scorer,
            ITextExtractor defaultTextExtractor,
            ITokenizer defaultTokenizer,
            Func <IIndexSnapshot <TKey>, Task>[]?indexModifiedActions)
        {
            this.indexNavigatorPool      = new IndexNavigatorPool(scorer);
            this.indexOptions            = indexOptions;
            this.itemTokenizationOptions = itemTokenizationOptions ?? throw new ArgumentNullException(nameof(itemTokenizationOptions));
            this.IndexNodeFactory        = indexNodeFactory ?? throw new ArgumentNullException(nameof(indexNodeFactory));
            this.queryParser             = queryParser ?? throw new ArgumentNullException(nameof(queryParser));
            this.DefaultTextExtractor    = defaultTextExtractor;
            this.DefaultTokenizer        = defaultTokenizer ?? throw new ArgumentNullException(nameof(defaultTokenizer));
            this.indexModifiedActions    = indexModifiedActions;
            this.idPool      = new IdPool <TKey>();
            this.FieldLookup = new IndexedFieldLookup(
                this.itemTokenizationOptions.GetAllConfiguredFields(),
                defaultTextExtractor,
                defaultTokenizer);

            this.Root = this.IndexNodeFactory.CreateRootNode();
        }
Example #2
0
        public IndexNodeMutation(int depth, IndexNode node, IIndexNodeFactory indexNodeFactory)
            : this(depth, indexNodeFactory)
        {
            this.original      = node;
            this.IntraNodeText = node.IntraNodeText;

            this.HasMatches    = node.HasMatches;
            this.HasChildNodes = node.HasChildNodes;
        }
Example #3
0
        /// <summary>
        /// Replaces the default <see cref="IIndexNodeFactory"/> implementation used creating index nodes.
        /// </summary>
        public FullTextIndexBuilder <TKey> WithIndexNodeFactory(IIndexNodeFactory indexNodeFactory)
        {
            if (indexNodeFactory is null)
            {
                throw new ArgumentNullException(nameof(indexNodeFactory));
            }

            this.indexNodeFactory = indexNodeFactory;

            return(this);
        }
Example #4
0
        private IndexNode DeserializeNode(IIndexNodeFactory nodeFactory, int depth)
        {
            var textLength     = this.reader.ReadInt32();
            var matchCount     = this.reader.ReadInt32();
            var childNodeCount = this.reader.ReadInt32();
            var intraNodeText  = textLength == 0 ? null : this.reader.ReadChars(textLength);
            var childNodes     = childNodeCount > 0 ? ImmutableDictionary.CreateBuilder <char, IndexNode>() : null;
            var matches        = matchCount > 0 ? ImmutableDictionary.CreateBuilder <int, ImmutableList <IndexedWord> >() : null;

            for (var i = 0; i < childNodeCount; i++)
            {
                var matchChar = this.reader.ReadChar();
                childNodes !.Add(matchChar, this.DeserializeNode(nodeFactory, depth + 1));
            }

            var locationMatches = new List <WordLocation>(50);

            for (var itemMatch = 0; itemMatch < matchCount; itemMatch++)
            {
                var itemId     = this.reader.ReadInt32();
                var fieldCount = this.reader.ReadInt32();

                var indexedWords = ImmutableList.CreateBuilder <IndexedWord>();

                for (var fieldMatch = 0; fieldMatch < fieldCount; fieldMatch++)
                {
                    var fieldId       = this.reader.ReadByte();
                    var locationCount = this.reader.ReadInt32();

                    locationMatches.Clear();

                    // Resize the collection immediately if required to prevent multiple resizes during deserialization
                    if (locationMatches.Capacity < locationCount)
                    {
                        locationMatches.Capacity = locationCount;
                    }

                    this.ReadLocations(locationCount, locationMatches);

                    indexedWords.Add(new IndexedWord(fieldId, locationMatches.ToArray()));
                }

                matches !.Add(itemId, indexedWords.ToImmutable());
            }

            return(nodeFactory.CreateNode(
                       intraNodeText,
                       childNodes?.ToImmutable() ?? ImmutableDictionary <char, IndexNode> .Empty,
                       matches?.ToImmutable() ?? ImmutableDictionary <int, ImmutableList <IndexedWord> > .Empty));
        }
Example #5
0
        public FullTextIndex(
            FullTextIndexConfiguration <TKey> options,
            IIndexNodeFactory indexNodeFactory = null,
            ITokenizerFactory tokenizerFactory = null,
            IQueryParser queryParser           = null)
        {
            this.indexNodeFactory = indexNodeFactory ?? new IndexNodeFactory();
            this.tokenizerFactory = tokenizerFactory ?? new TokenizerFactory();
            this.queryParser      = queryParser ?? new QueryParser();

            this.indexNodeFactory.Configure(options);

            this.IdPool      = new IdPool <TKey>();
            this.FieldLookup = new IndexedFieldLookup();
            this.Root        = this.indexNodeFactory.CreateNode();
        }
Example #6
0
 private IndexNodeMutation(int depth, IIndexNodeFactory indexNodeFactory)
 {
     this.depth            = depth;
     this.indexNodeFactory = indexNodeFactory;
 }
Example #7
0
 public IndexMutation(IndexNode root, IIndexNodeFactory indexNodeFactory)
 {
     this.root = new IndexNodeMutation(0, root, indexNodeFactory);
 }
Example #8
0
 public IndexNode(IIndexNodeFactory indexNodeFactory, int depth, IndexSupportLevelKind indexSupportLevel)
 {
     this.indexNodeFactory  = indexNodeFactory;
     this.Depth             = depth;
     this.indexSupportLevel = indexSupportLevel;
 }