public void Index_a_document_using_generic_syntax()
        {
            var stockItem = new StockItem
                            {
                                Id = 1,
                                Title = "Edam",
                                Description = "Tasty spherical cheese from Holland",
                                Price = 12.34M,
                                Categories = new Dictionary<string, string> {
                                                                                {"Country", "Holland"},
                                                                                {"PriceRange", "11-20"}
                                                                            }
                            };

            var document = new Document<StockItem>(stockItem.Id.ToString(), stockItem)
                .AddFields(x => x.Title, x => x.Description)
                .AddVariable(0, stockItem.Price)
                .AddCategories(stockItem.Categories);

            index.AddDocument(document);

            var query = new Query<StockItem>("title:Edam");
            var searchResult = index.Search(query);

            var resultStockItem = searchResult.Results.First().Obj;

            Assert.AreEqual("Edam", resultStockItem.Title);
            Assert.AreEqual(12.34, resultStockItem.Price);
        }
 public void Then_document_should_be_returned()
 {
     var document = new Document("id").AddField("key", "value");
     Index.AddDocument(document);
     var query = new Query("key:value").WithFields("*");
     var searchResult = Index.Search(query);
     searchResult.Results.Count().Should().Be(1);
     searchResult.Results.First().Fields["key"].Should().Be("value");
 }
 public void Then_result_should_contain_highlighted_snippet()
 {
     Index.AddFunction(1, "-km(query.var[0], query.var[1], doc.var[0], doc.var[1])");
     var doc = new Document("id").AddField("key", "value of the market is over two thousand pounds");
     Index.AddDocument(doc);
     var query = new Query("key:market").WithFields("*").WithSnippetFromFields("key");
     var searchResult = Index.Search(query);
     searchResult.Results.First().Snippets["key"].Should().Contain("<b>market</b>");
 }
 public void Then_document_should_be_returned()
 {
     var document = new Document<TestClass>("id", new TestClass { Key = "value" }).AddAllFields();
     Index.AddDocument(document);
     var query = new Query<TestClass>("value").WithSearchFields(x => x.Foo, x => x.Key).WithAllFields();
     var searchResult = Index.Search(query);
     var testClass = searchResult.Results.First().Obj;
     testClass.Key.Should().Be("value");
 }
 public void Then_document_should_be_returned()
 {
     var doc1 = new Document("id1").AddField("key", "value").AddCategory("cat", "1");
     var doc2 = new Document("id2").AddField("key", "value").AddCategory("cat", "2");
     Index.AddDocuments(doc1, doc2);
     var query = new Query("key:value").WithFields("*").WithCategoryFilter("cat", "1");
     var searchResult = Index.Search(query);
     searchResult.Results.Count().Should().Be(1);
     searchResult.Results.First().DocId.Should().Be("id1");
 }
        public void Then_variables_should_be_returned()
        {
            var document = new Document("id").AddField("key", "value");
            Index.AddDocument(document);
            TankTopClient.StatusCode.Should().Be(HttpStatusCode.OK);
            var search = new Query("key:value").WithVariables();

            Index.UpdateVariables("id", new Dictionary<int, float> { { 2, 5 } });

            var searchResult = Index.Search(search);
            searchResult.Results.First().Variables[2].Should().BeInRange(5, 5);
        }
 public void Then_document_should_be_deleted()
 {
     var document = new Document("1").AddField("key", "value");
     Index.AddDocument(document);
     TankTopClient.StatusCode.Should().Be(HttpStatusCode.OK);
     var search = new Query("key:value").WithFields("*");
     var searchResult = Index.Search(search);
     searchResult.Results.Count().Should().Be(1);
     Index.DeleteDocument("1");
     TankTopClient.StatusCode.Should().Be(HttpStatusCode.OK);
     searchResult = Index.Search(search);
     searchResult.Results.Count().Should().Be(0);
 }
        public void Index_a_document_using_non_generic_syntax()
        {
            var stockItem = new StockItem
                            {
                                Id = 1,
                                Title = "Edam",
                                Description = "Tasty spherical cheese from Holland",
                                Price = 12.34M,
                                Categories = new Dictionary<string, string> {
                                                                                {"Country", "Holland"},
                                                                                {"PriceRange", "11-20"}
                                                                            }
                            };

            var document = new Document(stockItem.Id.ToString())
                .AddField("title", stockItem.Title)
                .AddField("description", stockItem.Description)
                .AddVariable(0, stockItem.Price)
                .AddCategories(stockItem.Categories);

            index.AddDocument(document);

            var query = new Query("title:Edam").WithAllFields().WithVariables();
            var searchResult = index.Search(query);
            var resultDocument = searchResult.Results.First();

            var resultStockItem = new StockItem
                                  {
                                      Id = int.Parse(resultDocument.DocId),
                                      Title = resultDocument.Fields["title"],
                                      Description = resultDocument.Fields["description"],
                                      Price = (decimal)resultDocument.Variables[0],
                                      Categories = resultDocument.Categories
                                  };

            Assert.AreEqual("Edam", resultStockItem.Title);
            Assert.AreEqual(12.34, resultStockItem.Price);
        }
 public void Then_document_should_be_indexed()
 {
     var document = new Document("id").AddField("key", "value");
     Index.AddDocument(document);
     TankTopClient.StatusCode.Should().Be(HttpStatusCode.OK);
 }
 public void Then_mock_ITankTopClient()
 {
     var mockTankTopClient = Substitute.For<ITankTopClient>();
     var myIndex = new Index { Name = "MyIndex", TankTopClient = mockTankTopClient };
     var document = new Document("id").AddField("key", "value");
     myIndex.AddDocument(document);
     mockTankTopClient.Received().AddDocument("MyIndex", document);
 }