Exemplo n.º 1
0
        public void Search_Boolean_Debug()
        {
            ISearchResult result = index.Search($"evenDay: true");

            result.Any();
            Assert.That(result.TotalCount, Is.EqualTo(490));
        }
Exemplo n.º 2
0
        public SearchResult Search(string query, int skip = 0, int take = 20)
        {
            //TODO: Throw exception on invalid query.
            //if (string.IsNullOrWhiteSpace(query))
            //    Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Must specify a query.");

            ISearchResult result = index
                                   .Search(query)
                                   .Skip(skip)
                                   .Take(take);

            //TODO: extract contenttype based on configuration.
            SearchResult searchResult = new SearchResult(result
                                                         .Select(hit => pipeline.ExecuteAfterGet(hit.Json, (string)hit.Json.contentType, pipeline.CreateContext((string)hit.Json.contentType, (JObject)hit.Json)))
                                                         .ToArray(), result.TotalCount);

            performance.LogAsync("search", new
            {
                totalTime  = (long)result.TotalTime.TotalMilliseconds,
                searchTime = (long)result.SearchTime.TotalMilliseconds,
                loadTime   = (long)result.LoadTime.TotalMilliseconds,
                query, skip, take,
                results = result.TotalCount
            });
            return(searchResult);
        }
Exemplo n.º 3
0
        public void Search_FixedRange()
        {
            ISearchResult result = index.Search("created: [2000-01-10 TO 2000-01-14]");

            result.Any();

            Assert.That(result.TotalCount, Is.EqualTo(5));
        }
Exemplo n.º 4
0
        public void Search_Range_ReturnsPercent(string range, int count)
        {
            ISearchResult result = index.Search($"arr.@count: {range}");

            result.Any();
            Assert.That(result.TotalCount, Is.EqualTo(count));
        }
Exemplo n.º 5
0
 public void Search_ForMustangWithSpecifiedFields_Returns()
 {
     dynamic[] result = index
                        .Search("locode: MA*")
                        .Documents.ToArray();
     Assert.That(result, Has.Length.EqualTo(4));
 }
        public async void WriteContext_MakesDocumentsAvailable()
        {
            var config = index.Configuration;

            config
            .SetTypeResolver("Type")
            .SetAreaResolver("Area")
            .ForAll()
            .SetIdentity("Id");

            using (ILuceneWriteContext writer = index.Writer.WriteContext(1024))
            {
                await writer.Write(JObject.FromObject(new { Id = new Guid("00000000-0000-0000-0000-000000000001"), Type = "Person", Name = "John", LastName = "Doe", Area = "Foo" }));

                await writer.Write(JObject.FromObject(new { Id = new Guid("00000000-0000-0000-0000-000000000002"), Type = "Person", Name = "Peter", LastName = "Pan", Area = "Foo" }));

                await writer.Write(JObject.FromObject(new { Id = new Guid("00000000-0000-0000-0000-000000000003"), Type = "Person", Name = "Alice", Area = "Foo" }));

                await writer.Write(JObject.FromObject(new { Id = new Guid("00000000-0000-0000-0000-000000000004"), Type = "Car", Brand = "Ford", Model = "Mustang", Number = 5, Area = "Foo" }));

                await writer.Write(JObject.FromObject(new { Id = new Guid("00000000-0000-0000-0000-000000000005"), Type = "Car", Brand = "Dodge", Model = "Charger", Number = 10, Area = "Foo" }));

                await writer.Write(JObject.FromObject(new { Id = new Guid("00000000-0000-0000-0000-000000000006"), Type = "Car", Brand = "Chevrolet", Model = "Camaro", Number = 15, Area = "Foo" }));

                await writer.Write(JObject.FromObject(new { Id = new Guid("00000000-0000-0000-0000-000000000007"), Type = "Flower", Name = "Lilly", Meaning = "Majesty", Number = 5, Area = "Foo" }));

                await writer.Write(JObject.FromObject(new { Id = new Guid("00000000-0000-0000-0000-000000000008"), Type = "Flower", Name = "Freesia", Meaning = "Innocence", Number = 10, Area = "Foo" }));

                await writer.Write(JObject.FromObject(new { Id = new Guid("00000000-0000-0000-0000-000000000009"), Type = "Flower", Name = "Aster", Meaning = "Patience", Number = 15, Area = "Foo" }));
            }

            Assert.That(index.Search("*").Count(), Is.EqualTo(9));
        }
Exemplo n.º 7
0
 public void Search_ForMustangWithSpecifiedFields_Returns()
 {
     dynamic[] result = index
                        .Search("type: date")
                        .Sort(new Sort(new SortField("order", new FakeFieldComparerSource())))
                        .Documents.ToArray();
     Assert.That(result, Has.Length.EqualTo(9));
 }
Exemplo n.º 8
0
        public IEnumerable <JObject> Get(string contentType, int skip = 0, int take = 20)
        {
            JObject[] res = index.Search("contentType: " + contentType)
                            .Skip(skip).Take(take)
                            .Select(hit => hit.Json)
                            //Note: Execute the pipeline for each element found
                            .Select(json =>
            {
                using (PipelineContext context = pipeline.CreateContext(contentType, (JObject)json))
                {
                    return(pipeline.ExecuteAfterGet(json, contentType, context));
                }
            })
                            .Cast <JObject>().ToArray();

            return(res);

            //TODO: Execute pipeline for array
            //TODO: Paging and other neat stuff...
        }