예제 #1
0
        private IndexMergeResults CreateMergeIndexDefinition(List <MergeProposal> indexDataForMerge)
        {
            var indexMergeResults = new IndexMergeResults();

            foreach (var mergeProposal in indexDataForMerge.Where(m => m.ProposedForMerge.Count == 0 && m.MergedData != null))
            {
                indexMergeResults.Unmergables.Add(mergeProposal.MergedData.IndexName, mergeProposal.MergedData.Comment);
            }
            foreach (var mergeProposal in indexDataForMerge)
            {
                if (mergeProposal.ProposedForMerge.Count == 0)
                {
                    continue;
                }

                var mergeSuggestion = new MergeSuggestions();

                var selectExpressionDict = new Dictionary <string, Expression>();

                foreach (var curProposedData in mergeProposal.ProposedForMerge)
                {
                    foreach (var curExpr in curProposedData.SelectExpressions)
                    {
                        selectExpressionDict[curExpr.Key] = curExpr.Value;
                    }
                    mergeSuggestion.CanMerge.Add(curProposedData.IndexName);

                    DataDictionaryMerge(mergeSuggestion.MergedIndex.Stores, curProposedData.Stores);
                    DataDictionaryMerge(mergeSuggestion.MergedIndex.Indexes, curProposedData.Indexes);
                    DataDictionaryMerge(mergeSuggestion.MergedIndex.Analyzers, curProposedData.Analyzers);
                    DataDictionaryMerge(mergeSuggestion.MergedIndex.SortOptions, curProposedData.SortOptions);
                    DataDictionaryMerge(mergeSuggestion.MergedIndex.Suggestions, curProposedData.Suggestions);
                    DataDictionaryMerge(mergeSuggestion.MergedIndex.TermVectors, curProposedData.TermVectors);
                    DataDictionaryMerge(mergeSuggestion.MergedIndex.SpatialIndexes, curProposedData.SpatialIndexes);
                }

                mergeSuggestion.MergedIndex.Map = mergeProposal.ProposedForMerge[0].BuildExpression(selectExpressionDict);

                if (mergeProposal.ProposedForMerge.Count > 1)
                {
                    indexMergeResults.Suggestions.Add(mergeSuggestion);
                }
                if ((mergeProposal.ProposedForMerge.Count == 1) && (mergeProposal.ProposedForMerge[0].IsSuitedForMerge == false))
                {
                    const string comment = "Can't find any other index to merge this with";
                    indexMergeResults.Unmergables.Add(mergeProposal.ProposedForMerge[0].IndexName, comment);
                }
            }
            indexMergeResults = ExcludePartialResults(indexMergeResults);
            return(indexMergeResults);
        }
예제 #2
0
        private IndexMergeResults CreateMergeIndexDefinition(List <MergeProposal> indexDataForMerge)
        {
            var indexMergeResults = new IndexMergeResults();

            foreach (var mergeProposal in indexDataForMerge.Where(m => m.ProposedForMerge.Count == 0 && m.MergedData != null))
            {
                indexMergeResults.Unmergables.Add(mergeProposal.MergedData.IndexName, mergeProposal.MergedData.Comment);
            }
            foreach (var mergeProposal in indexDataForMerge)
            {
                if (mergeProposal.ProposedForMerge.Count == 0)
                {
                    continue;
                }

                var mergeSuggestion = new MergeSuggestions();

                var selectExpressionDict = new Dictionary <string, Expression>();

                foreach (var curProposedData in mergeProposal.ProposedForMerge)
                {
                    foreach (var curExpr in curProposedData.SelectExpressions)
                    {
                        selectExpressionDict[curExpr.Key] = curExpr.Value;
                    }
                    mergeSuggestion.CanMerge.Add(curProposedData.IndexName);

                    DataDictionaryMerge(mergeSuggestion.MergedIndex.Stores, curProposedData.Stores);
                    DataDictionaryMerge(mergeSuggestion.MergedIndex.Indexes, curProposedData.Indexes);
                    DataDictionaryMerge(mergeSuggestion.MergedIndex.Analyzers, curProposedData.Analyzers);
                    DataDictionaryMerge(mergeSuggestion.MergedIndex.SortOptions, curProposedData.SortOptions);
                    DataDictionaryMerge(mergeSuggestion.MergedIndex.Suggestions, curProposedData.Suggestions);
                    DataDictionaryMerge(mergeSuggestion.MergedIndex.TermVectors, curProposedData.TermVectors);
                    DataDictionaryMerge(mergeSuggestion.MergedIndex.SpatialIndexes, curProposedData.SpatialIndexes);
                    var fields1 = mergeSuggestion.MergedIndex.Fields;
                    var fields2 = curProposedData.Index.Fields;
                    mergeSuggestion.MergedIndex.Fields = fields1.Union(fields2).ToList();
                }

                mergeSuggestion.Collection      = mergeProposal.ProposedForMerge[0].Collection ?? mergeProposal.ProposedForMerge[0].FromExpression.ToString();
                mergeSuggestion.MergedIndex.Map = mergeProposal.ProposedForMerge[0].BuildExpression(selectExpressionDict);

                if (mergeProposal.ProposedForMerge.Count > 1)
                {
                    var matchingExistingIndexes = mergeProposal.ProposedForMerge.Where(x =>
                                                                                       AreSelectClausesTheSame(x, selectExpressionDict) &&
                                                                                       DictionaryExtensions.ContentEquals(x.Stores, mergeSuggestion.MergedIndex.Stores) &&
                                                                                       DictionaryExtensions.ContentEquals(x.Indexes, mergeSuggestion.MergedIndex.Indexes) &&
                                                                                       DictionaryExtensions.ContentEquals(x.Analyzers, mergeSuggestion.MergedIndex.Analyzers) &&
                                                                                       DictionaryExtensions.ContentEquals(x.SortOptions, mergeSuggestion.MergedIndex.SortOptions) &&
                                                                                       DictionaryExtensions.ContentEquals(x.Suggestions, mergeSuggestion.MergedIndex.Suggestions) &&
                                                                                       DictionaryExtensions.ContentEquals(x.TermVectors, mergeSuggestion.MergedIndex.TermVectors) &&
                                                                                       DictionaryExtensions.ContentEquals(x.SpatialIndexes, mergeSuggestion.MergedIndex.SpatialIndexes))
                                                  .OrderBy(x => x.IndexName.StartsWith("Auto/", StringComparison.InvariantCultureIgnoreCase))
                                                  .ToList();

                    if (matchingExistingIndexes.Count > 0)
                    {
                        var surpassingIndex = matchingExistingIndexes.First();
                        mergeSuggestion.SurpassingIndex = surpassingIndex.IndexName;

                        mergeSuggestion.MergedIndex = null;
                        mergeSuggestion.CanMerge.Clear();
                        mergeSuggestion.CanDelete = mergeProposal.ProposedForMerge.Except(new[]
                        {
                            surpassingIndex
                        }).Select(x => x.IndexName).ToList();
                    }

                    indexMergeResults.Suggestions.Add(mergeSuggestion);
                }
                if ((mergeProposal.ProposedForMerge.Count == 1) && (mergeProposal.ProposedForMerge[0].IsSuitedForMerge == false))
                {
                    const string comment = "Can't find any other index to merge this with";
                    indexMergeResults.Unmergables.Add(mergeProposal.ProposedForMerge[0].IndexName, comment);
                }
            }
            indexMergeResults = ExcludePartialResults(indexMergeResults);
            return(indexMergeResults);
        }