Esempio n. 1
0
        private IndexSearchOptions ToIndexSearchOptions(SearchOptions searchOptions)
        {
            var indexSearchOptions = new IndexSearchOptions();

            indexSearchOptions.SearchBy(MakePluralSingular(nameof(searchOptions.Colors)), searchOptions.Colors.Select(c => c.Id.ToString()).ToList());
            indexSearchOptions.SearchBy(MakePluralSingular(nameof(searchOptions.Sizes)), searchOptions.Sizes.Select(c => c.Id.ToString()).ToList());

            return(indexSearchOptions);
        }
Esempio n. 2
0
        public void Search_WhenSearchingByANonExistentField_ReturnsNoResults()
        {
            //Arrange
            var document = new IndexDocument()
            {
                Id     = Guid.NewGuid(),
                Fields =
                {
                    { "Color", "Red"   },
                    { "Size",  "Large" }
                }
            };

            var document2 = new IndexDocument()
            {
                Id     = Guid.NewGuid(),
                Fields =
                {
                    { "Color", "Red"    },
                    { "Size",  "Medium" }
                }
            };

            var document3 = new IndexDocument()
            {
                Id     = Guid.NewGuid(),
                Fields =
                {
                    { "Color", "Blue"  },
                    { "Size",  "Small" }
                }
            };

            _sut.Index(document);
            _sut.Index(document2);
            _sut.Index(document3);

            var searchOptions = new IndexSearchOptions();
            var fieldName     = Guid.NewGuid().ToString();

            searchOptions.SearchBy(fieldName, new List <string>()
            {
                "Small", "Medium"
            });

            //Act
            var result = _sut.Search(searchOptions);

            //Assert
            var documentResults = result.DocumentResults;

            Assert.IsNotNull(documentResults);
            Assert.AreEqual(0, documentResults.Count());
        }
Esempio n. 3
0
        public void IndexerPerformanceTest()
        {
            var documents = Enumerable.Range(0, 50000)
                            .Select(i => new IndexDocument()
            {
                Id = Guid.NewGuid(), Fields =
                {
                    { "Size",  GetRandomSize()  },
                    { "Color", GetRandomColor() },
                }
            })
                            .ToList();

            documents.ForEach(d =>
            {
                _sut.Index(d);
            });

            var sw = new Stopwatch();

            sw.Start();
            var searchOptions = new IndexSearchOptions();

            searchOptions.SearchBy("Color", new List <string>()
            {
                "Red"
            });

            var results = _sut.Search(searchOptions);

            sw.Stop();
            Assert.True(sw.ElapsedMilliseconds < 100);
            Console.WriteLine($"Total Milliseconds: {sw.ElapsedMilliseconds}");

            var documentResults = results.DocumentResults;
            var count           = documentResults.Count();
            var facetCount      = results.FacetResults["Color"].First().Count;

            Console.WriteLine($"Document Count: {count}");
            Console.WriteLine($"Facet Count: {facetCount}");
        }
Esempio n. 4
0
        public void Search_MulitpleValuesForMultipleFields()
        {
            //Arrange
            var document = new IndexDocument()
            {
                Id     = Guid.NewGuid(),
                Fields =
                {
                    { "Color", "Red"   },
                    { "Size",  "Large" }
                }
            };

            var document2 = new IndexDocument()
            {
                Id     = Guid.NewGuid(),
                Fields =
                {
                    { "Color", "Red"    },
                    { "Size",  "Medium" }
                }
            };

            var document3 = new IndexDocument()
            {
                Id     = Guid.NewGuid(),
                Fields =
                {
                    { "Color", "Blue"  },
                    { "Size",  "Small" }
                }
            };

            var document4 = new IndexDocument()
            {
                Id     = Guid.NewGuid(),
                Fields =
                {
                    { "Color", "Blue"   },
                    { "Size",  "Medium" }
                }
            };

            var document5 = new IndexDocument()
            {
                Id     = Guid.NewGuid(),
                Fields =
                {
                    { "Color", "Green" },
                    { "Size",  "Large" }
                }
            };

            _sut.Index(document);
            _sut.Index(document2);
            _sut.Index(document3);
            _sut.Index(document4);
            _sut.Index(document5);

            var searchOptions = new IndexSearchOptions();

            searchOptions.SearchBy("Size", new List <string>()
            {
                "Small", "Medium"
            });
            searchOptions.SearchBy("Color", new List <string>()
            {
                "Red", "Blue"
            });

            //Act
            var result = _sut.Search(searchOptions);

            //Assert
            var documentResults = result.DocumentResults;

            Assert.IsNotNull(documentResults);
            Assert.AreEqual(3, documentResults.Count());
            Assert.AreEqual(document2, documentResults.First(x => x.Id == document2.Id));
            Assert.AreEqual(document3, documentResults.First(x => x.Id == document3.Id));
            Assert.AreEqual(document4, documentResults.First(x => x.Id == document4.Id));

            var facetResults = result.FacetResults;

            Assert.IsNotNull(facetResults);
            Assert.AreEqual(1, facetResults["Size"].First(f => f.FacetName == "Small").Count);
            Assert.AreEqual(2, facetResults["Size"].First(f => f.FacetName == "Medium").Count);

            Assert.AreEqual(1, facetResults["Color"].First(f => f.FacetName == "Red").Count);
            Assert.AreEqual(2, facetResults["Color"].First(f => f.FacetName == "Blue").Count);
        }