/// <summary> /// Equals the specified other. /// </summary> /// <param name="other">The other.</param> /// <param name="compareIndexIds">allow caller to choose whether to include the index Id in the comparison</param> /// <param name="ignoreFormatting">Comparision ignores formatting in both of the definitions</param> /// <param name="ignoreMaxIndexOutput">Comparision ignores MaxIndexOutputsPerDocument</param> /// <returns></returns> public bool Equals(IndexDefinition other, bool compareIndexIds = true, bool ignoreFormatting = false, bool ignoreMaxIndexOutput = false) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } if (compareIndexIds && !Equals(other.IndexId, IndexId)) { return(false); } bool mapsReduceEquals; if (ignoreFormatting) { #if !DNXCORE50 var comparer = new IndexPrettyPrinterEqualityComparer(); mapsReduceEquals = Maps.SequenceEqual(other.Maps, comparer) && comparer.Equals(Reduce, other.Reduce); #else mapsReduceEquals = Maps.SequenceEqual(other.Maps) && Reduce.Equals(other.Reduce); #endif } else { mapsReduceEquals = Maps.SequenceEqual(other.Maps) && Equals(other.Reduce, Reduce); } return(mapsReduceEquals && (ignoreMaxIndexOutput || other.MaxIndexOutputsPerDocument == MaxIndexOutputsPerDocument) && DictionaryExtensions.ContentEquals(other.Stores, Stores) && DictionaryExtensions.ContentEquals(other.Indexes, Indexes) && DictionaryExtensions.ContentEquals(other.Analyzers, Analyzers) && DictionaryExtensions.ContentEquals(other.SortOptions, SortOptions) && SetExtensions.ContentEquals(other.SuggestionsOptions, SuggestionsOptions) && DictionaryExtensions.ContentEquals(other.TermVectors, TermVectors) && DictionaryExtensions.ContentEquals(other.SpatialIndexes, SpatialIndexes)); }
private bool CompareIndexFieldOptions(IndexData index1Data, IndexData index2Data) { if (SortOptionsMatch(index1Data.SortOptions, index2Data.SortOptions) == false) { return(false); } string[] intersectNames = index2Data.SelectExpressions.Keys.Intersect(index1Data.SelectExpressions.Keys).ToArray(); if (DataDictionaryCompare(index1Data.Stores, index2Data.Stores, intersectNames) == false) { return(false); } if (DataDictionaryCompare(index1Data.Analyzers, index2Data.Analyzers, intersectNames) == false) { return(false); } if (SetExtensions.ContentEquals(index1Data.SuggestionsOptions, index2Data.SuggestionsOptions) == false) { return(false); } if (DataDictionaryCompare(index1Data.Indexes, index2Data.Indexes, intersectNames) == false) { return(false); } if (DataDictionaryCompare(index1Data.TermVectors, index2Data.TermVectors, intersectNames) == false) { return(false); } if (DataDictionaryCompare(index1Data.SpatialIndexes, index2Data.SpatialIndexes, intersectNames) == false) { return(false); } return(true); }
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); DataSetMerge(mergeSuggestion.MergedIndex.SuggestionsOptions, curProposedData.SuggestionsOptions); 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) && SortOptionsMatch(x.SortOptions, mergeSuggestion.MergedIndex.SortOptions) && SetExtensions.ContentEquals(x.SuggestionsOptions, mergeSuggestion.MergedIndex.SuggestionsOptions) && 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); }