public void MultiIndex_Simple_Search() { var analyzer = new StandardAnalyzer(Version.LUCENE_30); using (var luceneDir1 = new RandomIdRAMDirectory()) using (var luceneDir2 = new RandomIdRAMDirectory()) using (var luceneDir3 = new RandomIdRAMDirectory()) using (var luceneDir4 = new RandomIdRAMDirectory()) using (var indexer1 = new TestBaseIndex(luceneDir1, analyzer)) using (var indexer2 = new TestBaseIndex(luceneDir2, analyzer)) using (var indexer3 = new TestBaseIndex(luceneDir3, analyzer)) using (var indexer4 = new TestBaseIndex(luceneDir4, analyzer)) { indexer1.IndexItem(ValueSet.FromObject(1.ToString(), "content", new { item1 = "value1", item2 = "The agitated zebras gallop back and forth in short, panicky dashes, then skitter off into the absolute darkness." })); indexer2.IndexItem(ValueSet.FromObject(1.ToString(), "content", new { item1 = "value2", item2 = "The festival lasts five days and celebrates the victory of good over evil, light over darkness, and knowledge over ignorance." })); indexer3.IndexItem(ValueSet.FromObject(1.ToString(), "content", new { item1 = "value3", item2 = "They are expected to confront the darkness and show evidence that they have done so in their papers" })); indexer4.IndexItem(ValueSet.FromObject(1.ToString(), "content", new { item1 = "value4", item2 = "Scientists believe the lake could be home to cold-loving microbial life adapted to living in total darkness." })); indexer3.IndexItem(ValueSet.FromObject(2.ToString(), "content", new { item1 = "value3", item2 = "Scotch scotch scotch, i love scotch" })); indexer4.IndexItem(ValueSet.FromObject(2.ToString(), "content", new { item1 = "value4", item2 = "60% of the time, it works everytime" })); var searcher = new MultiIndexSearcher("testSearcher", new[] { indexer1, indexer2, indexer3, indexer4 }, analyzer); var result = searcher.Search("darkness"); Assert.AreEqual(4, result.TotalItemCount); foreach (var r in result) { Console.WriteLine("Score = " + r.Score); } } }
public void Can_Delete() { using (var elasticsearch = new ElasticsearchInside.Elasticsearch(settings => settings .EnableLogging() .SetPort(9200) .SetElasticsearchStartTimeout(180)).ReadySync()) { ElasticSearchConfig config = new ElasticSearchConfig(new ConnectionSettings(elasticsearch.Url)); using (var indexer = new TestBaseIndex(config, new FieldDefinitionCollection())) { for (var i = 0; i < 10; i++) { indexer.IndexItem(new ValueSet(i.ToString(), "content", new Dictionary <string, IEnumerable <object> > { { "item1", new List <object>(new[] { "value1" }) }, { "item2", new List <object>(new[] { "value2" }) } })); } indexer.DeleteFromIndex("9"); indexer._client.Value.Indices.Refresh(Indices.Index(indexer.indexAlias)); Assert.AreEqual(9, indexer.DocumentCount); } } }
public void MultiIndex_Field_Count() { var analyzer = new StandardAnalyzer(Version.LUCENE_30); using (var luceneDir1 = new RandomIdRAMDirectory()) using (var luceneDir2 = new RandomIdRAMDirectory()) using (var luceneDir3 = new RandomIdRAMDirectory()) using (var luceneDir4 = new RandomIdRAMDirectory()) using (var indexer1 = new TestBaseIndex(luceneDir1, analyzer) { RunAsync = false }) using (var indexer2 = new TestBaseIndex(luceneDir2, analyzer) { RunAsync = false }) using (var indexer3 = new TestBaseIndex(luceneDir3, analyzer) { RunAsync = false }) using (var indexer4 = new TestBaseIndex(luceneDir4, analyzer) { RunAsync = false }) { indexer1.IndexItem(ValueSet.FromObject(1.ToString(), "content", new { item1 = "hello", item2 = "The agitated zebras gallop back and forth in short, panicky dashes, then skitter off into the absolute darkness." })); indexer2.IndexItem(ValueSet.FromObject(1.ToString(), "content", new { item1 = "world", item2 = "The festival lasts five days and celebrates the victory of good over evil, light over darkness, and knowledge over ignorance." })); indexer3.IndexItem(ValueSet.FromObject(1.ToString(), "content", new { item1 = "here", item2 = "They are expected to confront the darkness and show evidence that they have done so in their papers" })); indexer4.IndexItem(ValueSet.FromObject(1.ToString(), "content", new { item1 = "are", item2 = "Scientists believe the lake could be home to cold-loving microbial life adapted to living in total darkness." })); indexer3.IndexItem(ValueSet.FromObject(2.ToString(), "content", new { item3 = "some", item2 = "Scotch scotch scotch, i love scotch" })); indexer4.IndexItem(ValueSet.FromObject(2.ToString(), "content", new { item4 = "values", item2 = "60% of the time, it works everytime" })); var searcher = new MultiIndexSearcher("testSearcher", new[] { indexer1, indexer2, indexer3, indexer4 }, analyzer); var result = searcher.GetAllIndexedFields(); //will be item1 , item2, item3, and item4 Assert.AreEqual(4, result.Count()); foreach (var s in new[] { "item1", "item2", "item3", "item4" }) { Assert.IsTrue(result.Contains(s)); } } }
public void Can_Add_Same_Document_Twice_Without_Duplication() { using (var elasticsearch = new ElasticsearchInside.Elasticsearch(settings => settings .EnableLogging() .SetElasticsearchStartTimeout(180)).ReadySync()) { ElasticSearchConfig config = new ElasticSearchConfig(new ConnectionSettings(elasticsearch.Url)); using (var indexer = new TestBaseIndex(config, new FieldDefinitionCollection())) { var value = new ValueSet(1.ToString(), "content", new Dictionary <string, IEnumerable <object> > { { "item1", new List <object>(new[] { "value1" }) }, { "item2", new List <object>(new[] { "value2" }) } }); indexer.IndexItem(value); indexer.IndexItem(value); indexer._client.Value.Indices.Refresh(Indices.Index(indexer.indexAlias)); Assert.AreEqual(1, indexer.DocumentCount); } } }