示例#1
0
        public async Task GetNameByFilter()
        {
            var employeeEric = await _employeeRepository.AddAsync(EmployeeGenerator.Generate(name: "Eric J. Smith"), o => o.ImmediateConsistency());

            var employeeBlake = await _employeeRepository.AddAsync(EmployeeGenerator.Generate(name: "Blake Niemyjski"), o => o.ImmediateConsistency());

            var results = await _employeeRepository.GetByCriteriaAsync("name:blake");

            Assert.Equal(1, results.Total);
            Assert.True(results.Documents.All(d => d.Name == employeeBlake.Name));

            results = await _employeeRepository.GetByCriteriaAsync("name:\"Blake Niemyjski\"");

            Assert.Equal(1, results.Total);
            Assert.True(results.Documents.All(d => d.Name == employeeBlake.Name));

            results = await _employeeRepository.GetByCriteriaAsync("name:Niemy* name:eric");

            Assert.Equal(2, results.Total);

            results = await _employeeRepository.GetByCriteriaAsync("name:J*");

            Assert.Equal(1, results.Total);
            Assert.True(results.Documents.All(d => d.Name == employeeEric.Name));

            results = await _employeeRepository.GetByCriteriaAsync("name:*");

            Assert.Equal(2, results.Total);
            Assert.Equal(2, results.Hits.Sum(h => h.Score));

            await Assert.ThrowsAsync <FormatException>(async() => {
                await _employeeRepository.GetByCriteriaAsync("name:");
            });

            // In this example we want to search a quoted string (E.G., GET /url).
            results = await _employeeRepository.GetByCriteriaAsync("name:\"Blake /profile.url\"");

            Assert.Equal(0, results.Total);
        }