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 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; }
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; }
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" })); }
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 void GetPackagesSkipSelect() { var provider = new LuceneDataProvider(new RAMDirectory(), Version.LUCENE_30); var options = SetUpRequestWithOptions("/api/odata/Packages?$select=Id&$skip=1"); var queryable = provider.AsQueryable(() => new LucenePackage(_ => new MemoryStream())).Select(x => x.ToODataPackage()); var result = options.ApplyTo(queryable, new ODataQuerySettings {HandleNullPropagation = HandleNullPropagationOption.False}); Assert.That(result.OfType<object>().ToList().Count(), Is.EqualTo(0)); repo.VerifyAll(); }
public void GetPackagesSkipSelect() { var provider = new LuceneDataProvider(new RAMDirectory(), Version.LUCENE_30); var options = SetUpRequestWithOptions("/api/odata/Packages?$select=Id&$skip=1"); var queryable = provider.AsQueryable(() => new LucenePackage(_ => new MemoryStream())).Select(x => x.ToODataPackage()); var result = options.ApplyTo(queryable, new ODataQuerySettings { HandleNullPropagation = HandleNullPropagationOption.False }); Assert.That(result.OfType <object>().ToList().Count(), Is.EqualTo(0)); repo.VerifyAll(); }
public void TestBaseSetUp() { packagePathResolver = new Mock<IPackagePathResolver>(); loader = new Mock<ILucenePackageRepository>(MockBehavior.Strict); fileSystem = new Mock<IFileSystem>(); packagePathResolver.Setup(p => p.GetPackageDirectory(It.IsAny<IPackage>())).Returns("package-dir"); packagePathResolver.Setup(p => p.GetPackageFileName(It.IsAny<IPackage>())).Returns((Func<IPackage, string>)(pkg => pkg.Id)); var dir = new RAMDirectory(); provider = new LuceneDataProvider(dir, Version.LUCENE_30); indexWriter = provider.IndexWriter; datasource = provider.AsQueryable(() => new LucenePackage(fileSystem.Object)); }
public void TestBaseSetUp() { packagePathResolver = new Mock <IPackagePathResolver>(); loader = new Mock <ILucenePackageRepository>(MockBehavior.Strict); fileSystem = new Mock <IFileSystem>(); packagePathResolver.Setup(p => p.GetPackageDirectory(It.IsAny <IPackage>())).Returns("package-dir"); packagePathResolver.Setup(p => p.GetPackageDirectory(It.IsAny <string>(), It.IsAny <SemanticVersion>())).Returns("package-dir"); packagePathResolver.Setup(p => p.GetPackageFileName(It.IsAny <IPackage>())).Returns((Func <IPackage, string>)(pkg => pkg.Id)); packagePathResolver.Setup(p => p.GetPackageFileName(It.IsAny <string>(), It.IsAny <SemanticVersion>())).Returns((Func <string, SemanticVersion, string>)((id, version) => id + "." + version)); var dir = new RAMDirectory(); provider = new LuceneDataProvider(dir, Version.LUCENE_30); indexWriter = provider.IndexWriter; datasource = provider.AsQueryable(() => new LucenePackage(fileSystem.Object)); }
public SearchResult<ContactDocument> Search(string searchQuery) { using (var provider = new LuceneDataProvider(LuceneSearch.LuceneDirectory, Version.LUCENE_30)) { provider.Settings.EnableMultipleEntities = false; var queryParser = new MultiFieldParser<ContactDocument>(Version.LUCENE_30, new ReflectionDocumentMapper<ContactDocument>(Version.LUCENE_30)); var query = queryParser.Parse(searchQuery); var queryable = provider.AsQueryable<ContactDocument>(); var results = queryable.Where(query); return new SearchResult<ContactDocument> { SearchTerm = searchQuery, Results = results.ToList() }; } }
public SearchResult<ContactDocument> Search(string searchQuery) { using (var provider = new LuceneDataProvider(LuceneSearch.LuceneDirectory, Version.LUCENE_30)) { provider.Settings.EnableMultipleEntities = false; var queryParser = provider.CreateQueryParser<ContactDocument>(); queryParser.DefaultSearchProperty = "All"; queryParser.DefaultOperator = Lucene.Net.QueryParsers.QueryParser.Operator.AND; var query = queryParser.Parse(searchQuery); var queryable = provider.AsQueryable<ContactDocument>(); var results = queryable.Where(query); return new SearchResult<ContactDocument> { SearchTerm = searchQuery, Results = results.ToList() }; } }
public void CreatesIndex() { var provider = new LuceneDataProvider(new RAMDirectory(), Version.LUCENE_30); Assert.That(provider.AsQueryable <A>().Count(), Is.EqualTo(0)); }
public void EqualToEnum() { var count = provider.AsQueryable <Item>().Count(i => i.Enum == SampleEnum.Things); Assert.That(count, Is.EqualTo(1)); }
public void CreatesIndex() { var provider = new LuceneDataProvider(new RAMDirectory(), Version.LUCENE_30); Assert.That(provider.AsQueryable<A>().Count(), Is.EqualTo(0)); }