/// <summary> /// Toes the index definition. /// </summary> public IndexDefinition ToIndexDefinition(DocumentConvention convention, bool validateMap = true) { if (Map == null && validateMap) { throw new InvalidOperationException( string.Format("Map is required to generate an index, you cannot create an index without a valid Map property (in index {0}).", GetType().Name)); } string querySource = (typeof(TDocument) == typeof(object) || ContainsWhereEntityIs(Map.Body)) ? "docs" : "docs." + convention.GetTypeTagName(typeof(TDocument)); var indexDefinition = new IndexDefinition { Reduce = IndexDefinitionHelper.PruneToFailureLinqQueryAsStringToWorkableCode <TDocument, TReduceResult>(Reduce, convention, "results", translateIdentityProperty: false), TransformResults = IndexDefinitionHelper.PruneToFailureLinqQueryAsStringToWorkableCode <TDocument, TReduceResult>(TransformResults, convention, "results", translateIdentityProperty: Reduce == null), Indexes = ConvertToStringDictionary(Indexes), Stores = ConvertToStringDictionary(Stores), SortOptions = ConvertToStringDictionary(SortOptions), Analyzers = ConvertToStringDictionary(Analyzers) }; if (Map != null) { indexDefinition.Map = IndexDefinitionHelper.PruneToFailureLinqQueryAsStringToWorkableCode <TDocument, TReduceResult>(Map, convention, querySource, translateIdentityProperty : true); } return(indexDefinition); }
protected void AddMap <TSource>(Expression <Func <IEnumerable <TSource>, IEnumerable> > expression) { maps.Add(() => { string querySource = typeof(TSource) == typeof(object) ? "docs" : "docs." + Conventions.GetTypeTagName(typeof(TSource)); return(IndexDefinitionHelper.PruneToFailureLinqQueryAsStringToWorkableCode <TSource, TReduceResult>(expression, Conventions, querySource, translateIdentityProperty: true)); }); }
/// <summary> /// Toes the index definition. /// </summary> /// <param name="convention">The convention.</param> /// <returns></returns> public IndexDefinition ToIndexDefinition(DocumentConvention convention) { if (Map == null) { throw new InvalidOperationException( "Map is required to generate an index, you cannot create an index without a valid Map property (in index " + this.GetType().Name + ")."); } string querySource = (typeof(TDocument) == typeof(object) || ContainsWhereEntityIs(Map.Body)) ? "docs" : "docs." + convention.GetTypeTagName(typeof(TDocument)); return(new IndexDefinition { Map = IndexDefinitionHelper.PruneToFailureLinqQueryAsStringToWorkableCode(Map, convention, querySource, translateIdentityProperty: true), Reduce = IndexDefinitionHelper.PruneToFailureLinqQueryAsStringToWorkableCode(Reduce, convention, "results", translateIdentityProperty: false), TransformResults = IndexDefinitionHelper.PruneToFailureLinqQueryAsStringToWorkableCode(TransformResults, convention, "results", translateIdentityProperty: false), Indexes = ConvertToStringDictionary(Indexes), Stores = ConvertToStringDictionary(Stores), SortOptions = ConvertToStringDictionary(SortOptions), Analyzers = ConvertToStringDictionary(Analyzers) }); }
/// <summary> /// Toes the index definition. /// </summary> public IndexDefinition ToIndexDefinition(DocumentConvention convention, bool validateMap = true) { if (Map == null && validateMap) { throw new InvalidOperationException( string.Format("Map is required to generate an index, you cannot create an index without a valid Map property (in index {0}).", indexName)); } try { if (Reduce != null) { IndexDefinitionHelper.ValidateReduce(Reduce); } string querySource = (typeof(TDocument) == typeof(object) || ContainsWhereEntityIs()) ? "docs" : "docs." + convention.GetTypeTagName(typeof(TDocument)); var indexDefinition = new IndexDefinition { Reduce = IndexDefinitionHelper.PruneToFailureLinqQueryAsStringToWorkableCode <TDocument, TReduceResult>(Reduce, convention, "results", translateIdentityProperty: false), Indexes = ConvertToStringDictionary(Indexes), Stores = ConvertToStringDictionary(Stores), SortOptions = ConvertToStringDictionary(SortOptions), Analyzers = ConvertToStringDictionary(Analyzers), Suggestions = ConvertToStringDictionary(Suggestions), TermVectors = ConvertToStringDictionary(TermVectors), SpatialIndexes = ConvertToStringDictionary(SpatialIndexes), DisableInMemoryIndexing = DisableInMemoryIndexing, MaxIndexOutputsPerDocument = MaxIndexOutputsPerDocument, LockMode = LockMode, }; if (convention.PrettifyGeneratedLinqExpressions) { indexDefinition.Reduce = IndexPrettyPrinter.TryFormat(indexDefinition.Reduce); } foreach (var indexesString in IndexesStrings) { if (indexDefinition.Indexes.ContainsKey(indexesString.Key)) { throw new InvalidOperationException("There is a duplicate key in indexes: " + indexesString.Key); } indexDefinition.Indexes.Add(indexesString); } foreach (var storeString in StoresStrings) { if (indexDefinition.Stores.ContainsKey(storeString.Key)) { throw new InvalidOperationException("There is a duplicate key in stores: " + storeString.Key); } indexDefinition.Stores.Add(storeString); } foreach (var analyzerString in AnalyzersStrings) { if (indexDefinition.Analyzers.ContainsKey(analyzerString.Key)) { throw new InvalidOperationException("There is a duplicate key in analyzers: " + analyzerString.Key); } indexDefinition.Analyzers.Add(analyzerString); } foreach (var termVectorString in TermVectorsStrings) { if (indexDefinition.TermVectors.ContainsKey(termVectorString.Key)) { throw new InvalidOperationException("There is a duplicate key in term vectors: " + termVectorString.Key); } indexDefinition.TermVectors.Add(termVectorString); } foreach (var spatialString in SpatialIndexesStrings) { if (indexDefinition.SpatialIndexes.ContainsKey(spatialString.Key)) { throw new InvalidOperationException("There is a duplicate key in spatial indexes: " + spatialString.Key); } indexDefinition.SpatialIndexes.Add(spatialString); } foreach (var sortOption in SortOptionsStrings) { if (indexDefinition.SortOptions.ContainsKey(sortOption.Key)) { throw new InvalidOperationException("There is a duplicate key in sort options: " + sortOption.Key); } indexDefinition.SortOptions.Add(sortOption); } if (Map != null) { indexDefinition.Map = IndexDefinitionHelper.PruneToFailureLinqQueryAsStringToWorkableCode <TDocument, TReduceResult>( Map, convention, querySource, translateIdentityProperty: true); if (convention.PrettifyGeneratedLinqExpressions) { indexDefinition.Map = IndexPrettyPrinter.TryFormat(indexDefinition.Map); } } return(indexDefinition); } catch (Exception e) { throw new IndexCompilationException("Failed to create index " + indexName, e); } }
/// <summary> /// Toes the index definition. /// </summary> public IndexDefinition ToIndexDefinition(DocumentConvention convention, bool validateMap = true) { if (Map == null && validateMap) { throw new InvalidOperationException( string.Format("Map is required to generate an index, you cannot create an index without a valid Map property (in index {0}).", GetType().Name)); } if (Reduce != null) { IndexDefinitionHelper.ValidateReduce(Reduce); } string querySource = (typeof(TDocument) == typeof(object) || ContainsWhereEntityIs()) ? "docs" : "docs." + convention.GetTypeTagName(typeof(TDocument)); var indexDefinition = new IndexDefinition { Reduce = IndexDefinitionHelper.PruneToFailureLinqQueryAsStringToWorkableCode <TDocument, TReduceResult>(Reduce, convention, "results", translateIdentityProperty: false), #pragma warning disable 612,618 TransformResults = IndexDefinitionHelper.PruneToFailureLinqQueryAsStringToWorkableCode <TDocument, TReduceResult>(TransformResults, convention, "results", translateIdentityProperty: Reduce == null), #pragma warning restore 612,618 Indexes = ConvertToStringDictionary(Indexes), Stores = ConvertToStringDictionary(Stores), SortOptions = ConvertToStringDictionary(SortOptions), Analyzers = ConvertToStringDictionary(Analyzers), Suggestions = ConvertToStringDictionary(Suggestions), TermVectors = ConvertToStringDictionary(TermVectors), SpatialIndexes = ConvertToStringDictionary(SpatialIndexes) }; foreach (var indexesString in IndexesStrings) { if (indexDefinition.Indexes.ContainsKey(indexesString.Key)) { throw new InvalidOperationException("There is a duplicate key in indexes: " + indexesString.Key); } indexDefinition.Indexes.Add(indexesString); } foreach (var storeString in StoresStrings) { if (indexDefinition.Stores.ContainsKey(storeString.Key)) { throw new InvalidOperationException("There is a duplicate key in stores: " + storeString.Key); } indexDefinition.Stores.Add(storeString); } foreach (var analyzerString in AnalyzersStrings) { if (indexDefinition.Analyzers.ContainsKey(analyzerString.Key)) { throw new InvalidOperationException("There is a duplicate key in analyzers: " + analyzerString.Key); } indexDefinition.Analyzers.Add(analyzerString); } foreach (var termVectorString in TermVectorsStrings) { if (indexDefinition.TermVectors.ContainsKey(termVectorString.Key)) { throw new InvalidOperationException("There is a duplicate key in term vectors: " + termVectorString.Key); } indexDefinition.TermVectors.Add(termVectorString); } foreach (var spatialString in SpatialIndexesStrings) { if (indexDefinition.SpatialIndexes.ContainsKey(spatialString.Key)) { throw new InvalidOperationException("There is a duplicate key in spatial indexes: " + spatialString.Key); } indexDefinition.SpatialIndexes.Add(spatialString); } if (Map != null) { indexDefinition.Map = IndexDefinitionHelper.PruneToFailureLinqQueryAsStringToWorkableCode <TDocument, TReduceResult>(Map, convention, querySource, translateIdentityProperty : true); } return(indexDefinition); }