public void AnItemCanBeUpdatedInTheIndex()
        {
            TestDataGenerator tdg       = new TestDataGenerator();
            Directory         directory = new RAMDirectory();
            Analyzer          analyzer  = new StandardAnalyzer(Lucene.Net.Util.LuceneVersion.LUCENE_48);

            indexer = new LuceneIndexer(directory, analyzer);
            indexer.CreateIndex(tdg.AllData, true);

            // we need a searcher for this test
            LuceneIndexSearcher searcher = new LuceneIndexSearcher(directory, analyzer);

            // get the 1st item
            SearchOptions options = new SearchOptions("*****@*****.**", "Email");

            var initialResults = searcher.ScoredSearch(options);

            foreach (var item in initialResults.Results)
            {
                output.WriteLine($"{item.Score}\t{item.Document.Get("Id")}\t{item.Document.Get("FirstName")}\t{item.Document.Get("Email")}");
            }
            //Assert.Equal(1, initialResults.TotalHits);

            Document rambler = initialResults.Results.First().Document;

            // convert to ILuceneIndexable
            User user = new User()
            {
                Id        = int.Parse(rambler.Get("Id")),
                IndexId   = new Guid(rambler.Get("IndexId")),
                FirstName = rambler.Get("FirstName"),
                Surname   = rambler.Get("Surname"),
                Email     = rambler.Get("Email"),
                JobTitle  = rambler.Get("JobTitle")
            };

            // make an edit
            user.FirstName = "Duke";
            user.Surname   = "Nukem";

            // add the update to the indexer
            indexer.Update(user);

            // search again
            var endResults = searcher.ScoredSearch(options);

            foreach (var item in endResults.Results)
            {
                output.WriteLine($"{item.Score}\t{item.Document.Get("Id")}\t{item.Document.Get("FirstName")}\t{item.Document.Get("Email")}");
            }

            // Assert.Equal(1, endResults.TotalHits);
            Assert.Equal(user.IndexId.ToString(), endResults.Results.First().Document.Get("IndexId"));
            Assert.Equal(user.Id.ToString(), endResults.Results.First().Document.Get("Id"));
            Assert.Equal(user.FirstName, endResults.Results.First().Document.Get("FirstName"));
            Assert.Equal(user.Surname, endResults.Results.First().Document.Get("Surname"));
            directory.ClearLock("write.lock");
        }
Example #2
0
        public void AnItemCanBeRemovedFromTheIndex()
        {
            TestDataGenerator tdg       = new TestDataGenerator();
            Directory         directory = new RAMDirectory();
            Analyzer          analyzer  = new StandardAnalyzer(Lucene.Net.Util.LuceneVersion.LUCENE_48);

            _indexer = new LuceneIndexer(directory, analyzer);
            _indexer.CreateIndex(tdg.AllData);
            _indexer.Delete(tdg.AllData.First());
            Assert.True(tdg.AllData.Count > _indexer.Count());
            directory.ClearLock("write.lock");
        }
Example #3
0
        public void AnIndexCanBeCreated()
        {
            TestDataGenerator tdg       = new TestDataGenerator();
            Directory         directory = new RAMDirectory();

            Analyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.LuceneVersion.LUCENE_48);

            _indexer = new LuceneIndexer(directory, analyzer);
            _indexer.CreateIndex(tdg.AllData);
            Assert.Equal(2000, _indexer.Count());
            analyzer.Dispose();
            directory.ClearLock("write.lock");
            directory.Dispose();
        }
        public void AnItemCanBeAddedToTheIndex()
        {
            TestDataGenerator tdg       = new TestDataGenerator();
            Directory         directory = new RAMDirectory();
            Analyzer          analyzer  = new StandardAnalyzer(Lucene.Net.Util.LuceneVersion.LUCENE_48);

            indexer = new LuceneIndexer(directory, analyzer);
            indexer.CreateIndex(tdg.AllData, true);
            Assert.Equal(2000, indexer.Count());

            indexer.Add(tdg.ANewUser());

            Assert.Equal(2001, indexer.Count());
            directory.ClearLock("write.lock");
        }
Example #5
0
        public void AnItemCanBeUpdatedInTheIndex()
        {
            TestDataGenerator tdg       = new TestDataGenerator();
            Directory         directory = new RAMDirectory();
            Analyzer          analyzer  = new StandardAnalyzer(Lucene.Net.Util.LuceneVersion.LUCENE_48);

            _indexer = new LuceneIndexer(directory, analyzer);
            _indexer.CreateIndex(tdg.AllData);
            LuceneIndexSearcher searcher = new LuceneIndexSearcher(directory, analyzer, new MemoryCache(new MemoryCacheOptions()));

            SearchOptions options        = new SearchOptions("*****@*****.**", "Email");
            var           initialResults = searcher.ScoredSearch(options);

            foreach (var item in initialResults.Results)
            {
                _output.WriteLine($"{item.Score}\t{item.Document.Get("Id")}\t{item.Document.Get("FirstName")}\t{item.Document.Get("Email")}");
            }

            Document rambler = initialResults.Results.First().Document;
            User     user    = new User()
            {
                Id        = int.Parse(rambler.Get("Id")),
                FirstName = rambler.Get("FirstName"),
                Surname   = rambler.Get("Surname"),
                Email     = rambler.Get("Email"),
                JobTitle  = rambler.Get("JobTitle")
            };

            user.FirstName = "Duke";
            user.Surname   = "Nukem";
            _indexer.Update(user);
            var endResults = searcher.ScoredSearch(options);

            foreach (var item in endResults.Results)
            {
                _output.WriteLine($"{item.Score}\t{item.Document.Get("Id")}\t{item.Document.Get("FirstName")}\t{item.Document.Get("Email")}");
            }

            Assert.Equal(user.Id.ToString(), endResults.Results.First().Document.Get("Id"));
            Assert.Equal(user.FirstName, endResults.Results.First().Document.Get("FirstName"));
            Assert.Equal(user.Surname, endResults.Results.First().Document.Get("Surname"));
            directory.ClearLock("write.lock");
        }
Example #6
0
 public static void Init(TestContext context)
 {
     indexer.CreateIndex(tdg.AllData);
 }
 public LuceneIndexSearcherTests(TestDataGenerator tdg)
 {
     Indexer.CreateIndex(tdg.AllData);
 }
Example #8
0
 public void Initialize()
 {
     indexer = new LuceneIndexer(directory, analyzer);
     indexer.CreateIndex(tdg.AllData, true);
 }