Пример #1
0
 private void AddDocumentToIndex <T>(object document)
 {
     using (var session = _provider.OpenSession <T>(TypedFactory <T>(), new PieReflectionDocumentMapper <T>(Version.LUCENE_30, this)))
     {
         session.Add((T)document);
     }
 }
        public void MergesAnalyzersForSessionsOfDifferentTypes()
        {
            var provider = new LuceneDataProvider(new RAMDirectory(), Version.LUCENE_30);

            provider.OpenSession <A>();
            provider.OpenSession <B>();

            Assert.That(provider.Analyzer["Prop1"], Is.InstanceOf <SimpleAnalyzer>());
            Assert.That(provider.Analyzer["Prop2"], Is.InstanceOf <WhitespaceAnalyzer>());
        }
Пример #3
0
        public void StoreAndRetrieveById()
        {
            using (var session = provider.OpenSession <Item>())
            {
                session.Add(new Item {
                    Id = 100
                });
            }

            Assert.That(provider.AsQueryable <Item>().Count(), Is.EqualTo(1));
            Assert.That(provider.AsQueryable <Item>().First().Id, Is.EqualTo(100));
        }
        public override LuceneSession <TModel> OpenSession()
        {
            ISession <TModel>      nativeSession = luceneDataProvider.OpenSession(documentMapper);
            LuceneSession <TModel> session       = new LuceneSession <TModel>(nativeSession);

            return(session);
        }
Пример #5
0
        public void Demo()
        {
            var provider = new LuceneDataProvider(new RAMDirectory(), Version.LUCENE_30);

            using (var session = provider.OpenSession <Entity>())
            {
                session.Add(new Entity {
                    Text = "text is comprised of words"
                });
                session.Add(new Entity {
                    Text = "words compose text"
                });
                session.Add(new Entity {
                    Text = "completely unrelated"
                });
            }

            var mapper = new MoreLikeThisDocumentMapper <Entity>(Version.LUCENE_30);

            var query = provider.AsQueryable(mapper);

            var result = query.First(e => e.Text == "words");

            var moreLikeQuery   = mapper.MoreLike(result);
            var moreLikeResults = query.Where(moreLikeQuery).Select(e => e.Text).ToList();

            Assert.That(moreLikeResults, Is.EquivalentTo(new[] { "text is comprised of words", "words compose text" }));
        }
Пример #6
0
        public static void Main()
        {
            var directory = new RAMDirectory();

            var provider = new LuceneDataProvider(directory, Version.LUCENE_30);

            // add some documents
            using (var session = provider.OpenSession <Article>())
            {
                session.Add(new Article {
                    Author = "John Doe", BodyText = "some body text", PublishDate = DateTimeOffset.UtcNow
                });
            }

            var articles = provider.AsQueryable <Article>();

            var threshold = DateTimeOffset.UtcNow.Subtract(TimeSpan.FromDays(30));

            var articlesByJohn = from a in articles
                                 where a.Author == "John Doe" && a.PublishDate > threshold
                                 orderby a.Title
                                 select a;

            Console.WriteLine("Articles by John Doe: " + articlesByJohn.Count());

            var searchResults = from a in articles
                                where a.SearchText == "some search query"
                                select a;

            Console.WriteLine("Search Results: " + searchResults.Count());
        }
        public static void Main()
        {
            var directory = new RAMDirectory();

            var provider = new LuceneDataProvider(directory, Version.LUCENE_30);

            // add some documents
            using (var session = provider.OpenSession<Article>())
            {
                session.Add(new Article { Author = "John Doe", BodyText = "some body text", PublishDate = DateTimeOffset.UtcNow });
            }

            var articles = provider.AsQueryable<Article>();

            var threshold = DateTimeOffset.UtcNow.Subtract(TimeSpan.FromDays(30));

            var articlesByJohn = from a in articles
                          where a.Author == "John Smith" && a.PublishDate > threshold
                          orderby a.Title
                          select a;

            var searchResults = from a in articles
                                 where a.SearchText == "some search query"
                                 select a;

        }
Пример #8
0
        public void CommitInSessionAndDisposeProviderReleasesFiles()
        {
            var dir = "index." + DateTime.Now.Ticks;

            System.IO.Directory.CreateDirectory(dir);
            var provider = new LuceneDataProvider(FSDirectory.Open(dir), Version.LUCENE_30);

            using (provider)
            {
                using (var session = provider.OpenSession <Document>())
                {
                    session.Add(new Document {
                        Id = 1
                    });

                    session.Commit();

                    session.Add(new Document {
                        Id = 2
                    });
                }
            }

            TestDelegate call = () => System.IO.Directory.Delete(dir, true);

            Assert.That(call, Throws.Nothing);
        }
        public void Index(Directory directory)
        {
            IndexWriter.Unlock(directory);

            var provider     = new LuceneDataProvider(directory, Lucene.Net.Util.Version.LUCENE_30);
            var praticiens   = _praticienRepository.GetAll().Where(a => !a.IsIndexed).ToList();
            var itemsToIndex = new List <PraticienToIndexModel>();

            praticiens.ForEach(a =>
            {
                var item = PraticienWrapper.PraticienEntityToPraticienToIndexModel(a);

                itemsToIndex.Add(item);
            });

            var indexedIds = new List <string>();

            using (var session = provider.OpenSession <PraticienToIndexModel>())
            {
                foreach (var praticienToIndex in itemsToIndex)
                {
                    session.Add(praticienToIndex);
                    indexedIds.Add(praticienToIndex.Cin);
                    var indexedpraticien =
                        praticiens.First(
                            a =>
                            a.Cin.ToString().Equals(praticienToIndex.Cin, StringComparison.InvariantCultureIgnoreCase));
                    indexedpraticien.IsIndexed = true;
                    _praticienRepository.Update(indexedpraticien);
                }
                session.Commit();
            }
        }
Пример #10
0
        public static void Main()
        {
            var directory = new RAMDirectory();
            var writer    = new IndexWriter(directory, new StandardAnalyzer(Version.LUCENE_29), IndexWriter.MaxFieldLength.UNLIMITED);

            var provider = new LuceneDataProvider(directory, writer.Analyzer, Version.LUCENE_29, writer);

            // add some documents
            using (var session = provider.OpenSession <Article>())
            {
                session.Add(new Article {
                    Author = "John Doe", BodyText = "some body text", PublishDate = DateTimeOffset.UtcNow
                });
            }

            var articles = provider.AsQueryable <Article>();

            var threshold = DateTimeOffset.UtcNow.Subtract(TimeSpan.FromDays(30));

            var articlesByJohn = from a in articles
                                 where a.Author == "John Smith" && a.PublishDate > threshold
                                 orderby a.Title
                                 select a;

            var searchResults = from a in articles
                                where a.SearchText == "some search query"
                                select a;
        }
Пример #11
0
        public void OpenSessionThrowsWhenReadOnly()
        {
            var provider = new LuceneDataProvider(new RAMDirectory(), new SimpleAnalyzer(), Version.LUCENE_29);

            TestDelegate call = () => provider.OpenSession <Item>();

            Assert.That(call, Throws.InvalidOperationException);
        }
        public void OpenSessionThrowsWhenReadOnly()
        {
            var provider = new LuceneDataProvider(new RAMDirectory(), new SimpleAnalyzer(), Version.LUCENE_29);

            TestDelegate call = () => provider.OpenSession<Item>();

            Assert.That(call, Throws.InvalidOperationException);
        }
        public void OpenSessionWithoutWriterCreatesIndexWhenMissing()
        {
            var provider = new LuceneDataProvider(new RAMDirectory(), new SimpleAnalyzer(), Version.LUCENE_29);

            TestDelegate call = () => provider.OpenSession<Item>();

            Assert.That(call, Throws.Nothing);
        }
        public void OpenSessionThrowsWhenDocumentMapperDoesNotImplementModificationDetector()
        {
            var provider = new LuceneDataProvider(new RAMDirectory(), new SimpleAnalyzer(), Version.LUCENE_29);

            TestDelegate call = () => provider.OpenSession(MockRepository.GenerateStrictMock <IDocumentMapper <Item> >());

            Assert.That(call, Throws.ArgumentException.With.Property("ParamName").EqualTo("documentMapper"));
        }
        public void OpenSessionThrowsWhenDocumentMapperDoesNotImplementModificationDetector()
        {
            var provider = new LuceneDataProvider(new RAMDirectory(), new SimpleAnalyzer(), Version.LUCENE_29);

            TestDelegate call = () => provider.OpenSession(MockRepository.GenerateStrictMock<IDocumentMapper<Item>>());

            Assert.That(call, Throws.ArgumentException.With.Property("ParamName").EqualTo("documentMapper"));
        }
Пример #16
0
 protected void AddDocument <T>(T document) where T : new()
 {
     using (var session = provider.OpenSession <T>())
     {
         session.Add(document);
         session.Commit();
     }
 }
        public void OpenSessionWithoutWriterCreatesIndexWhenMissing()
        {
            var provider = new LuceneDataProvider(new RAMDirectory(), new SimpleAnalyzer(), Version.LUCENE_29);

            TestDelegate call = () => provider.OpenSession <Item>();

            Assert.That(call, Throws.Nothing);
        }
Пример #18
0
 public void AddRange(IEnumerable <T> items)
 {
     using (var session = _provider.OpenSession <T>(_documentMapper.Create, _documentMapper))
     {
         foreach (var item in items)
         {
             var key = item.Key();
             _objectLookup.Add(key, item);
             session.Add(item);
             var notify = item as INotifyPropertyChanged;
             if (notify != null)
             {
                 notify.PropertyChanged += notify_PropertyChanged;
             }
         }
         session.Commit();
     }
 }
Пример #19
0
 protected void AddUser(string username, string key = "", string[] roles = null)
 {
     using (var session = provider.OpenSession <ApiUser>())
     {
         session.Add(new ApiUser {
             Username = username, Key = key, Roles = roles
         });
     }
 }
Пример #20
0
        protected void InsertPackage(LucenePackage p)
        {
            p.Path = Path.Combine(packagePathResolver.Object.GetPackageDirectory(p),
                                  packagePathResolver.Object.GetPackageFileName(p));

            using (var s = provider.OpenSession(() => new LucenePackage(fileSystem.Object)))
            {
                s.Add(p);
            }
        }
Пример #21
0
 public void SetUp()
 {
     directory = new RAMDirectory();
     provider = new LuceneDataProvider(directory, Version.LUCENE_30);
     using (var session = provider.OpenSession<Item>())
     {
         session.Add(new Item { Id = "0", Enum = SampleEnum.Things, NumericEnum = SampleEnum.Things });
         session.Add(new Item { Id = "1", Enum = SampleEnum.Stuff, NumericEnum = SampleEnum.Stuff });
     }
 }
Пример #22
0
        //Save Log
        public override void SaveLog(List <RawLogData> data)
        {
            if (data == null)
            {
                log.Error("Error ");
                return;
            }

            try
            {
                var lst = GetAppLogsFromRawData(data);
                using (var session = appLogProvider.OpenSession <AppLog>())
                {
                    session.Add(lst.ToArray());
                }
            }
            catch (Exception ex)
            {
                log.Error(ex, "Error when processing Base Log - Message");
            }
        }
Пример #23
0
        public void Execute()
        {
            using (var provider = new LuceneDataProvider(LuceneSearch.LuceneDirectory, Lucene.Net.Util.Version.LUCENE_30))
            {
                provider.Settings.EnableMultipleEntities = false;

                using (var session = provider.OpenSession<ContactDocument>())
                {
                    var mapped = LuceneSearch.MapContactToDocument(contact);
                    session.Delete(mapped);
                }
            }  
        }
Пример #24
0
 public void SetUp()
 {
     directory = new RAMDirectory();
     provider  = new LuceneDataProvider(directory, Version.LUCENE_30);
     using (var session = provider.OpenSession <Item>())
     {
         session.Add(new Item {
             Id = "0", Enum = SampleEnum.Things, NumericEnum = SampleEnum.Things
         });
         session.Add(new Item {
             Id = "1", Enum = SampleEnum.Stuff, NumericEnum = SampleEnum.Stuff
         });
     }
 }
Пример #25
0
        public void CommitInSessionAndDisposeProviderReleasesFiles()
        {
            var dir = "index." + DateTime.Now.Ticks;
            System.IO.Directory.CreateDirectory(dir);
            var provider = new LuceneDataProvider(FSDirectory.Open(dir), Version.LUCENE_30);
            using (provider)
            {
                using (var session = provider.OpenSession<Document>())
                {
                    session.Add(new Document { Id = 1 });

                    session.Commit();

                    session.Add(new Document { Id = 2 });
                }
            }

            TestDelegate call = () => System.IO.Directory.Delete(dir, true);
            Assert.That(call, Throws.Nothing);
        }
        public void InitializeIndex()
        {
            var context = new AddressBookContext(connectionString);
            var contacts = context.Contacts
                .Include(c => c.Organisation)
                .Include(c => c.Department)
                .Include(c => c.Office.Address)
                .Include(c => c.PhoneNumbers)
                .Include(c => c.EmailAddresses);
            
            using (var provider = new LuceneDataProvider(LuceneSearch.LuceneDirectory, Lucene.Net.Util.Version.LUCENE_30))
            {
                provider.Settings.EnableMultipleEntities = false;

                using (var session = provider.OpenSession<ContactDocument>())
                {
                    var docs = contacts.Select(LuceneSearch.MapContactToDocument).ToArray();
                    
                    session.DeleteAll();
                    session.Add(docs);
                }
            }            
        }
Пример #27
0
 protected ISession <ApiUser> OpenSession()
 {
     return(provider.OpenSession <ApiUser>());
 }
        public void MergesAnalyzersForSessionsOfDifferentTypes()
        {
            var provider = new LuceneDataProvider(new RAMDirectory(), Version.LUCENE_30);

            provider.OpenSession<A>();
            provider.OpenSession<B>();

            Assert.That(provider.Analyzer["Prop1"], Is.InstanceOf<SimpleAnalyzer>());
            Assert.That(provider.Analyzer["Prop2"], Is.InstanceOf<WhitespaceAnalyzer>());
        }