Exemplo n.º 1
0
        public void UsingDuplicateFieldNameShouldThrowException()
        {
            var itemConfigBuilder = new ItemTokenizationOptionsBuilder <string, string>()
                                    .WithField("Field1", o => o)
                                    .WithField("Field2", o => o)
                                    .WithField("Field1", o => o)
                                    .WithKey(i => i);

            Assert.Throws <LiftiException>(() => new IndexedFieldLookup(itemConfigBuilder.Build().FieldTokenization, this.tokenizerFactoryMock.Object, TokenizationOptions.Default))
            .Message.Should().Be("Duplicate field name used: Field1. Field names must be unique across all item types registered with an index.");
        }
Exemplo n.º 2
0
        public void UsingMoreThan255IdsShouldThrowException()
        {
            var itemConfigBuilder = new ItemTokenizationOptionsBuilder <string, string>()
                                    .WithKey(i => i);

            for (var i = 0; i < 256; i++)
            {
                itemConfigBuilder = itemConfigBuilder.WithField("Field" + i, r => r);
            }

            Assert.Throws <LiftiException>(() => new IndexedFieldLookup(itemConfigBuilder.Build().FieldTokenization, this.tokenizerFactoryMock.Object, TokenizationOptions.Default))
            .Message.Should().Be("Only 255 distinct fields can currently be indexed");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates an <see cref="ItemTokenizationOptions{TItem, TKey}"/> configuration entry for an item of type <typeparamref name="TItem"/>
        /// in the index.
        /// </summary>
        /// <param name="idReader">
        /// A delegate capable of specifying all the required options for the item tokenization options.
        /// </param>
        public FullTextIndexBuilder <TKey> WithItemTokenization <TItem>(Func <ItemTokenizationOptionsBuilder <TItem, TKey>, ItemTokenizationOptionsBuilder <TItem, TKey> > optionsBuilder)
        {
            if (optionsBuilder is null)
            {
                throw new ArgumentNullException(nameof(optionsBuilder));
            }

            var builder = new ItemTokenizationOptionsBuilder <TItem, TKey>();

            this.itemTokenizationOptions.Add(optionsBuilder(builder).Build());

            return(this);
        }
Exemplo n.º 4
0
        public IndexedFieldLookupTests()
        {
            var itemConfig = new ItemTokenizationOptionsBuilder <string, string>()
                             .WithKey(i => i)
                             .WithField("Field1", r => r)
                             .WithField("Field2", r => r)
                             .WithField("Field3", r => r)
                             .WithField("FieldX", r => r, o => o.WithStemming())
                             .WithField("FieldY", r => r)
                             .Build();

            this.tokenizerFactoryMock = new Mock <ITokenizerFactory>();
            this.tokenizerFactoryMock.Setup(f => f.Create(TokenizationOptions.Default)).Returns(defaultTokenizer);
            this.tokenizerFactoryMock.Setup(f => f.Create(It.Is <TokenizationOptions>(o => o.Stemming))).Returns(stemmingTokenizer);

            this.sut = new IndexedFieldLookup(itemConfig.FieldTokenization, this.tokenizerFactoryMock.Object, TokenizationOptions.Default);
        }