Пример #1
0
        public List <DynamicQueryToIndexMatcher.Explanation> ExplainIndexSelection(IndexQueryServerSide query, out string indexName)
        {
            var map          = DynamicQueryMapping.Create(query);
            var explanations = new List <DynamicQueryToIndexMatcher.Explanation>();

            var dynamicQueryToIndex = new DynamicQueryToIndexMatcher(_indexStore);
            var match = dynamicQueryToIndex.Match(map, explanations);

            indexName = match.IndexName;

            return(explanations);
        }
Пример #2
0
        public List <DynamicQueryToIndexMatcher.Explanation> ExplainIndexSelection(string dynamicIndexName, IndexQueryServerSide query)
        {
            var collection   = dynamicIndexName.Substring(DynamicIndexPrefix.Length);
            var map          = DynamicQueryMapping.Create(collection, query);
            var explanations = new List <DynamicQueryToIndexMatcher.Explanation>();

            var dynamicQueryToIndex = new DynamicQueryToIndexMatcher(_indexStore);

            dynamicQueryToIndex.Match(map, explanations);

            return(explanations);
        }
Пример #3
0
        private bool TryMatchExistingIndexToQuery(DynamicQueryMapping map, out Index index)
        {
            var dynamicQueryToIndex = new DynamicQueryToIndexMatcher(_indexStore);

            var matchResult = dynamicQueryToIndex.Match(map);

            switch (matchResult.MatchType)
            {
            case DynamicQueryMatchType.Complete:
            case DynamicQueryMatchType.CompleteButIdle:
                index = _indexStore.GetIndex(matchResult.IndexName);
                if (index == null)
                {
                    // the auto index was deleted
                    break;
                }

                return(true);

            case DynamicQueryMatchType.Partial:
                // At this point, we found an index that has some fields we need and
                // isn't incompatible with anything else we're asking for
                // We need to clone that other index
                // We need to add all our requested indexes information to our cloned index
                // We can then use our new index instead

                var currentIndex = _indexStore.GetIndex(matchResult.IndexName);
                if (currentIndex != null)
                {
                    if (map.SupersededIndexes == null)
                    {
                        map.SupersededIndexes = new List <Index>();
                    }

                    map.SupersededIndexes.Add(currentIndex);

                    map.ExtendMappingBasedOn((AutoIndexDefinitionBase)currentIndex.Definition);
                }

                break;
            }

            index = null;
            return(false);
        }