public void Partial_match_if_exact_is_required()
        {
            using (var db = CreateDocumentDatabase())
            {
                var mapping = DynamicQueryMapping.Create(new IndexQueryServerSide(@"from Users
where Name = 'arek'"));

                db.IndexStore.CreateIndex(mapping.CreateAutoIndexDefinition()).Wait();

                mapping = DynamicQueryMapping.Create(new IndexQueryServerSide(@"from Users
where exact(Name = 'arek')"));

                var matcher = new DynamicQueryToIndexMatcher(db.IndexStore);

                var result = matcher.Match(mapping, null);

                Assert.Equal(DynamicQueryMatchType.Partial, result.MatchType);
            }
        }
Exemplo n.º 2
0
        private string GetIndexNameFromCollectionAndField(string field)
        {
            var collection = GetStringQueryString("collection", false);

            if (string.IsNullOrEmpty(collection))
            {
                return(null);
            }
            var query = new IndexQueryServerSide(new QueryMetadata($"from {collection} select {field}", null, 0));
            var dynamicQueryToIndex = new DynamicQueryToIndexMatcher(Database.IndexStore);
            var match = dynamicQueryToIndex.Match(DynamicQueryMapping.Create(query));

            if (match.MatchType == DynamicQueryMatchType.Complete ||
                match.MatchType == DynamicQueryMatchType.CompleteButIdle)
            {
                return(match.IndexName);
            }
            throw new IndexDoesNotExistException($"There is no index to answer the following query: from {collection} select {field}");
        }
        public async Task Partial_match_if_analyzer_is_required()
        {
            Initialize();
            using (var db = CreateDocumentDatabase())
            {
                var mapping = DynamicQueryMapping.Create(new IndexQueryServerSide(@"from Users
where Name = 'arek'"));

                await db.IndexStore.CreateIndex(mapping.CreateAutoIndexDefinition(), Guid.NewGuid().ToString());

                mapping = DynamicQueryMapping.Create(new IndexQueryServerSide(@"from Users
where search(Name, 'arek')"));

                var matcher = new DynamicQueryToIndexMatcher(db.IndexStore);

                var result = matcher.Match(mapping, null);

                Assert.Equal(DynamicQueryMatchType.Partial, result.MatchType);
            }
        }
Exemplo n.º 4
0
        public void Should_match_auto_map_index_if_analyzed_field_isnt_used_in_where()
        {
            using (var db = CreateDocumentDatabase())
            {
                var mapping = DynamicQueryMapping.Create(new IndexQueryServerSide(@"
from LastFms
where search(Artist, ""Chri"") and Genre = ""jazz"""));

                db.IndexStore.CreateIndex(mapping.CreateAutoIndexDefinition(), Guid.NewGuid().ToString()).Wait();

                mapping = DynamicQueryMapping.Create(new IndexQueryServerSide(@"
from LastFms
where Genre = ""jazz""
select Artist"));

                var matcher = new DynamicQueryToIndexMatcher(db.IndexStore);

                var result = matcher.Match(mapping, null);

                Assert.Equal(DynamicQueryMatchType.Complete, result.MatchType);
            }
        }
Exemplo n.º 5
0
        public async Task Complete_but_idle_match_if_auto_map_index_is_idle()
        {
            using (var database = CreateDocumentDatabase())
            {
                var matcher = new DynamicQueryToIndexMatcher(database.IndexStore);

                var autoIndex = await database.IndexStore.CreateIndex(new AutoMapIndexDefinition("Users", new[]
                {
                    new AutoIndexField
                    {
                        Name = "FirstName",
                    }
                }));

                autoIndex.SetState(IndexState.Idle);

                var dynamicQuery = DynamicQueryMapping.Create(new IndexQueryServerSide("from Users where FirstName = 'Arek'"));

                var result = matcher.Match(dynamicQuery, null);

                Assert.Equal(DynamicQueryMatchType.CompleteButIdle, result.MatchType);
            }
        }
        public MatchingAutoMapIndexesForDynamicQueries()
        {
            _documentDatabase = CreateDocumentDatabase();

            _sut = new DynamicQueryToIndexMatcher(_documentDatabase.IndexStore);
        }
        public void Initialize([CallerMemberName] string caller = null)
        {
            _documentDatabase = CreateDocumentDatabase(caller: caller);

            _sut = new DynamicQueryToIndexMatcher(_documentDatabase.IndexStore);
        }