public void Past() { IndexManager.PurgeIndexes(); var expected = new List <SampleDate> { new SampleDate {//0 DocDate = new DateTime(2019, 1, 1) }, new SampleDate {//1 DocDate = new DateTime(2019, 2, 1) }, new SampleDate {//2 DocDate = new DateTime(2019, 3, 7) } }; IndexManager.BulkInsert(expected); var searchData = new FindRequest <SampleDate>(0, 10); var results = searchData .Should(SearchClause <SampleDate> .LessThan(x => x.DocDate, new DateTime(2019, 1, 7))) .Sort(x => x.DocDate) .Execute(); var actual = results.Documents.ToList(); //range Assert.Single(actual); Assert.Equal(expected[0].DocDate, actual[0].DocDate); }
public void Nested() { IndexManager.PurgeIndexes(); var expected = new List <SampleNest> { new SampleNest { Id = "1", Title = "Nested Test", Items = new List <NestedEntity> { new NestedEntity { Created = new DateTime(2019, 3, 7), Code = 3, Data = "item" } } } }; IndexManager.BulkInsert(expected); var searchData = new FindRequest <SampleNest>(0, 10); var results = searchData .Must(SearchClause <SampleNest> .Range(x => x.Items, new DateTime(2019, 2, 7), new DateTime(2019, 6, 1), x => x.Items[0].Created)) .Must(SearchClause <SampleNest> .Range(x => x.Items, 2, 5, x => x.Items[0].Code)) .Must(SearchClause <SampleNest> .Term(x => x.Items, "item", x => x.Items[0].Data)) .Execute(); var actual = results.Documents.ToList(); Assert.Equal(expected.Count, actual.Count); }
public void LessThan() { IndexManager.PurgeIndexes(); var expected = new List <SampleWeight> { new SampleWeight {//0 Weight = 100 }, new SampleWeight {//1 Weight = 110 }, new SampleWeight {//2 Weight = 120 } }; IndexManager.BulkInsert(expected); var searchData = new FindRequest <SampleWeight>(0, 10); var results = searchData .Should(SearchClause <SampleWeight> .LessThan(x => x.Weight, 110)) .Sort(x => x.Weight) .Execute(); var actual = results.Documents.ToList(); //range Assert.Single(actual); Assert.Equal(expected[0].Weight, actual[0].Weight); }
public void InRange() { IndexManager.PurgeIndexes(); var expected = new List <SampleWeight> { new SampleWeight {//0 Weight = 100 }, new SampleWeight {//1 Weight = 110 }, new SampleWeight {//2 Weight = 120 }, new SampleWeight {//3 Weight = 130 }, new SampleWeight {//4 Weight = 200 }, new SampleWeight {//5 Weight = 210 }, new SampleWeight {//6 Weight = 220 }, new SampleWeight {//7 Weight = 230 }, }; IndexManager.BulkInsert(expected); var searchData = new FindRequest <SampleWeight>(0, 10); var results = searchData .Should(SearchClause <SampleWeight> .Range(x => x.Weight, 119, 201)) .Sort(x => x.Weight) .Execute(); var actual = results.Documents.ToList(); //range Assert.Equal(3, actual.Count); Assert.Equal(expected[2].Weight, actual[0].Weight); Assert.Equal(expected[3].Weight, actual[1].Weight); Assert.Equal(expected[4].Weight, actual[2].Weight); }
public void DateRange() { IndexManager.PurgeIndexes(); var expected = new List <SampleDate> { new SampleDate {//0 DocDate = new DateTime(2019, 1, 1) }, new SampleDate {//1 DocDate = new DateTime(2019, 2, 1) }, new SampleDate {//2 DocDate = new DateTime(2019, 3, 7) }, new SampleDate {//3 DocDate = new DateTime(2019, 4, 7) }, new SampleDate {//4 DocDate = new DateTime(2019, 5, 7) }, new SampleDate {//5 DocDate = new DateTime(2019, 6, 7) } }; IndexManager.BulkInsert(expected); var searchData = new FindRequest <SampleDate>(0, 10); var results = searchData .Should(SearchClause <SampleDate> .Range(x => x.DocDate, new DateTime(2019, 2, 7), new DateTime(2019, 6, 1))) .Sort(x => x.DocDate) .Execute(); var actual = results.Documents.ToList(); //range Assert.Equal(3, actual.Count); Assert.Equal(expected[2].DocDate, actual[0].DocDate); Assert.Equal(expected[3].DocDate, actual[1].DocDate); Assert.Equal(expected[4].DocDate, actual[2].DocDate); }
public void Get() { IndexManager.PurgeIndexes(); var expected = new List <SampleDocument> { new SampleDocument {//0 Id = "1", Content = "my content" } }; IndexManager.BulkInsert(expected); var searchData = new FindRequest <SampleDocument>(0, 10); var results = searchData .Get(SearchClause <SampleDocument> .Match(x => x.Content, "my")); var actual = results.Documents.ToList(); Assert.Single(actual); Assert.Equal(expected[0].Id, actual[0].Id); }
public void GeoSearch() { IndexManager.PurgeIndexes(); var expected = new List <SampleLocation> { new SampleLocation { Description = "alpha", Location = new Nest.GeoLocation(38.044842, 23.728171) }, new SampleLocation { Description = "beta", Location = new Nest.GeoLocation(38.045316, 23.725822) }, new SampleLocation { Description = "gama", Location = new Nest.GeoLocation(38.044378, 23.723365) }, new SampleLocation { Description = "out", Location = new Nest.GeoLocation(37.862905, 22.924569) } }; IndexManager.BulkInsert(expected); var searchData = new FindRequest <SampleLocation>(0, 10); var results = searchData .Should(SearchClause <SampleLocation> .Distance(x => x.Location, 38.044631, 23.724513, 500)) .GeoSort(x => x.Location, 38.044631, 23.724513) .Execute(); var actual = results.Documents.ToList(); Assert.Equal(3, actual.Count); Assert.Equal(expected[2].Description, actual[0].Description); Assert.Equal(expected[1].Description, actual[1].Description); Assert.Equal(expected[0].Description, actual[2].Description); }
public void Term() { IndexManager.PurgeIndexes(); var expected = new List <SampleItem> { new SampleItem {//0 Id = "1", Code = "A", Sequence = 1 }, new SampleItem {//1 Id = "2", Code = "B", Sequence = 2 } }; IndexManager.BulkInsert(expected); var searchData = new FindRequest <SampleItem>(0, 10); var results = searchData .Must(SearchClause <SampleItem> .Term(x => x.Code, "A")) .Execute(); var actual = results.Documents.ToList(); Assert.Single(actual); Assert.Equal(expected[0].Id, actual[0].Id); searchData = new FindRequest <SampleItem>(0, 10); results = searchData .Must(SearchClause <SampleItem> .Term(x => x.Sequence, 2)) .Execute(); actual = results.Documents.ToList(); Assert.Single(actual); Assert.Equal(expected[1].Id, actual[0].Id); }
public void Quoted() { IndexManager.PurgeIndexes(); var expected = new List <SampleDocument> { new SampleDocument { Id = "1", Sort = "1", Content = @"This a test", Title = "Alpha", DocDate = new DateTime(2019, 11, 7) }, new SampleDocument { Id = "2", Sort = "2", Content = @"Run a quoted test thisisasample", Title = "Alpha", DocDate = new DateTime(2019, 11, 7) }, new SampleDocument { Id = "3", Sort = "3", Content = @"no return test", Title = "Mex", DocDate = new DateTime(2019, 11, 7) }, new SampleDocument { Id = "4", Sort = "4", Content = @"find all of data", Title = "pep", DocDate = new DateTime(2019, 11, 1) }, new SampleDocument { Id = "5", Sort = "5", Content = @"date", Title = "date", DocDate = new DateTime(2019, 11, 7) } }; IndexManager.BulkInsert(expected); var searchData = new FindRequest <SampleDocument>(0, 10); var results = searchData .Must(SearchClause <SampleDocument> .Match(x => x.Content, "\"find all \" date return quoted test")) .Sort(x => x.Sort) .Execute(); var actual = results.Documents.ToList(); Assert.Equal(expected.Count, actual.Count); for (int i = 0; i < expected.Count; i++) { Assert.Equal(expected[i].Id, actual[i].Id); Assert.Equal(expected[i].Sort, actual[i].Sort); Assert.Equal(expected[i].Title, actual[i].Title); Assert.Equal(expected[i].DocDate, actual[i].DocDate); Assert.Equal(expected[i].Content, actual[i].Content); } }
public void InWildCard() { IndexManager.PurgeIndexes(); var expected = new List <SampleDocument> { new SampleDocument { Id = "1", Sort = "1", Content = @"This a test", Title = "Alpha", DocDate = new DateTime(2019, 11, 7) }, new SampleDocument { Id = "2", Sort = "2", Content = @"Run a prefix test thisisasample", Title = "Alpha", DocDate = new DateTime(2019, 11, 7) }, new SampleDocument { Id = "3", Sort = "3", Content = @"no return test", Title = "Mex", DocDate = new DateTime(2019, 11, 7) }, new SampleDocument { Id = "4", Sort = "4", Content = @"does not exist", Title = "pep", DocDate = new DateTime(2019, 11, 1) }, new SampleDocument { Id = "5", Sort = "5", Content = @"date", Title = "date", DocDate = new DateTime(2019, 11, 7) } }; IndexManager.BulkInsert(expected); var searchData = new FindRequest <SampleDocument>(0, 10); var results = searchData .Must(SearchClause <SampleDocument> .Wildcard(x => x.Content, "th*s")) .Sort(x => x.Sort) .Execute(); var actual = results.Documents.ToList(); Assert.Equal(2, actual.Count); Assert.Equal(expected[0].Id, actual[0].Id); Assert.Equal(expected[0].Sort, actual[0].Sort); Assert.Equal(expected[0].Title, actual[0].Title); Assert.Equal(expected[0].DocDate, actual[0].DocDate); Assert.Equal(expected[0].Content, actual[0].Content); Assert.Equal(expected[1].Id, actual[1].Id); Assert.Equal(expected[1].Sort, actual[1].Sort); Assert.Equal(expected[1].Title, actual[1].Title); Assert.Equal(expected[1].DocDate, actual[1].DocDate); Assert.Equal(expected[1].Content, actual[1].Content); }
public void Search() { IndexManager.PurgeIndexes(); var expected = new List <SampleDocument> { new SampleDocument { Id = "1", Sort = "1", Content = @"Omega", Title = "Alpha", DocDate = new DateTime(2019, 11, 7) }, new SampleDocument { Id = "2", Sort = "2", Content = @"delta", Title = "Alpha", DocDate = new DateTime(2019, 11, 7) }, new SampleDocument { Id = "3", Sort = "3", Content = @"thisfind", Title = "Mex", DocDate = new DateTime(2019, 11, 7) }, new SampleDocument { Id = "4", Sort = "4", Content = @"trit", Title = "pep", DocDate = new DateTime(2019, 11, 1) }, new SampleDocument { Id = "5", Sort = "5", Content = @"date", Title = "date", DocDate = new DateTime(2019, 11, 7) } }; IndexManager.BulkInsert(expected); var searchData = new FindRequest <SampleDocument>(0, 10); var results = searchData .Should(SearchClause <SampleDocument> .Term(x => x.Content, "thisfind")) .Should(SearchClause <SampleDocument> .Term(x => x.Title, "alpha")) .Should(SearchClause <SampleDocument> .GreaterThan(x => x.DocDate, new DateTime(2019, 11, 5))) .Sort(x => x.Sort) .Execute(); var actual = results.Documents.ToList(); Assert.Equal(4, actual.Count); Assert.Equal("1", actual[0].Id); Assert.Equal("2", actual[1].Id); Assert.Equal("3", actual[2].Id); Assert.Equal("5", actual[3].Id); }
public void ReIndexing() { IndexManager.PurgeIndexes(); var expected = new List <SampleDocument> { new SampleDocument { Id = "1", Sort = "1", Content = @"Omega", Title = "Alpha", DocDate = new DateTime(2019, 11, 7) }, new SampleDocument { Id = "2", Sort = "2", Content = @"delta", Title = "Alpha", DocDate = new DateTime(2019, 11, 7) }, new SampleDocument { Id = "3", Sort = "3", Content = @"thisfind", Title = "Mex", DocDate = new DateTime(2019, 11, 7) }, new SampleDocument { Id = "4", Sort = "4", Content = @"trit", Title = "pep", DocDate = new DateTime(2019, 11, 1) }, new SampleDocument { Id = "5", Sort = "5", Content = @"date", Title = "date", DocDate = new DateTime(2019, 11, 7) } }; IndexManager.BulkInsert(expected); Manager.Instance.AppVersion = "2"; IndexManager.ReIndex <SampleDocument>(); var searchData = new FindRequest <SampleDocument>(0, 10); var results = searchData .Sort(x => x.Sort) .Execute(); var actual = results.Documents.ToList(); Assert.Equal(expected.Count, actual.Count); for (int i = 0; i < expected.Count; i++) { Assert.Equal(expected[i].Id, actual[i].Id); Assert.Equal(expected[i].Sort, actual[i].Sort); Assert.Equal(expected[i].Title, actual[i].Title); Assert.Equal(expected[i].DocDate, actual[i].DocDate); Assert.Equal(expected[i].Content, actual[i].Content); } }