Пример #1
0
 public ITableIndex CreateIndex(IndexName indexName, string indexType, string[] columnNames, bool[] columnOrders)
 {
     MockTable table = (MockTable) GetTable(indexName.TableName);
     MockTableIndex index = new MockTableIndex(table, indexName, indexType, columnNames, columnOrders);
     indexes.Add(indexName, index);
     return index;
 }
Пример #2
0
        public ReadModelDescription(
            IndexName indexName)
        {
            if (indexName == null) throw new ArgumentNullException(nameof(indexName));

            IndexName = indexName;
        }
		public CreateIndexRequest(IndexName index, IndexState state) : this(index)
		{
			this.Settings = state.Settings;
			this.Mappings = state.Mappings;
			this.Aliases = state.Aliases;
			this.Similarity = state.Similarity;
			CreateIndexRequest.RemoveReadOnlySettings(this.Settings);
		}
		public Task<IShrinkIndexResponse> ShrinkIndexAsync(
			IndexName source,
			IndexName target,
			Func<ShrinkIndexDescriptor, IShrinkIndexRequest> selector = null,
			CancellationToken cancellationToken = default(CancellationToken)
		) => this.ShrinkIndexAsync(selector.InvokeOrDefault(new ShrinkIndexDescriptor(source, target)));
Пример #5
0
 /// <summary>
 /// <c>GET</c> request to the <c>ilm.explain_lifecycle</c> API, read more about this API online:
 /// <para></para>
 /// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-explain-lifecycle.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-explain-lifecycle.html</a>
 /// </summary>
 public Task <ExplainLifecycleResponse> ExplainLifecycleAsync(IndexName index, Func <ExplainLifecycleDescriptor, IExplainLifecycleRequest> selector = null, CancellationToken ct = default) => ExplainLifecycleAsync(selector.InvokeOrDefault(new ExplainLifecycleDescriptor(index: index)), ct);
Пример #6
0
 /// <summary>
 /// <c>POST</c> request to the <c>ilm.retry</c> API, read more about this API online:
 /// <para></para>
 /// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-retry-policy.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-retry-policy.html</a>
 /// </summary>
 public Task <RetryIlmResponse> RetryAsync(IndexName index, Func <RetryIlmDescriptor, IRetryIlmRequest> selector = null, CancellationToken ct = default) => RetryAsync(selector.InvokeOrDefault(new RetryIlmDescriptor(index: index)), ct);
Пример #7
0
 /// <summary>
 /// <c>POST</c> request to the <c>ilm.move_to_step</c> API, read more about this API online:
 /// <para></para>
 /// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-move-to-step.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-move-to-step.html</a>
 /// </summary>
 public Task <MoveToStepResponse> MoveToStepAsync(IndexName index, Func <MoveToStepDescriptor, IMoveToStepRequest> selector = null, CancellationToken ct = default) => MoveToStepAsync(selector.InvokeOrDefault(new MoveToStepDescriptor(index: index)), ct);
Пример #8
0
 public CountResponse GetCount(IndexName indexName)
 {
     return(_client.Count <TModel>(count => count.Index(indexName)));
 }
        public void Search_by_email_mapped_term_search_Test()
        {
            //ARRANGE
            var id = Guid.NewGuid();

            var dependencyResolver = new DependencyResolverMock();
            var client             = SearchClientFactory.GetClient();

            //create index name
            var indexName = String.Format("{0}_{1}", typeof(ParentTestClass).Name, id).ToLower();
            var index     = new IndexName {
                Name = indexName, Type = typeof(ParentTestClass)
            };

            //ACT
            try
            {
                var indexDescriptor = new CreateIndexDescriptor(index)
                                      .Mappings(map => map.Map <ParentTestClass>(m =>
                                                                                 m.AutoMap()
                                                                                 .Properties(prop => prop.Nested <ChildClass>(o =>
                                                                                                                              o.Name(parent => parent.Child))
                                                                                             )
                                                                                 .Properties(prop => prop.Keyword(kw => kw.Name(parent => parent.Email)))));
                var createIndexRequest = client.CreateIndex(indexDescriptor);

                var testClass = new ParentTestClass {
                    Email = "*****@*****.**"
                };
                testClass.Children.Add(new ChildClass());
                var createDocumentResponse = client.Create(testClass, d => d.Index(index)
                                                           .Type(typeof(ParentTestClass)));

                Thread.Sleep(1000);
                var indexReqiest  = new GetIndexRequest(index);
                var indexResponse = client.GetIndex(indexReqiest);
                var indices       = indexResponse.Indices.ToList();
                var first         = indices.First();
                var mappings      = first.Value.Mappings.First()
                                    .Value.Properties.Select(p => new { p.Key.Name, p.Value.Type, PropertyName = p.Value.Name });
                //ACT
                //Search
                var searchResponse = client
                                     .Search <ParentTestClass>(s =>
                                                               s.Query(q =>
                                                                       q.Term(m => m.Field(g => g.Email)
                                                                              .Value("*****@*****.**")))
                                                               .Index(index));

                var allRecords = client
                                 .Search <ParentTestClass>(q => q
                                                           .Index(Indices.Index(index)));

                //ASSERT
                Assert.IsTrue(searchResponse.IsValid);
                Assert.AreEqual(1, searchResponse.Documents.Count());
                Assert.AreEqual(testClass.Id, searchResponse.Documents.First().Id);
                Assert.AreEqual(testClass.Email, searchResponse.Documents.First().Email);
            }
            finally
            {
                var deleteIndexResult = client.DeleteIndex(index);
            }
        }
        public void Search_match_term_by_Id_Test()
        {
            //ARRANGE
            var id = Guid.NewGuid();
            //set up search client
            var dependencyResolver = new DependencyResolverMock();

            var client = SearchClientFactory.GetClient();

            //create index name
            var indexName = String.Format("{0}_{1}", typeof(ParentTestClass).Name, id).ToLower();
            var index     = new IndexName {
                Name = indexName, Type = typeof(ParentTestClass)
            };

            try
            {
                var indexDescriptor = new CreateIndexDescriptor(index)
                                      .Mappings(map => map.Map <ParentTestClass>(m =>
                                                                                 m.AutoMap()));

                var createIndexRequest = client.CreateIndex(indexDescriptor);

                var testClass = new ParentTestClass();
                testClass.Children.Add(new ChildClass());
                var createDocumentResponse = client.Create(testClass, d => d.Index(index)
                                                           .Type(typeof(ParentTestClass)));

                Thread.Sleep(1000);

                //ACT
                //Search
                var searchMatchResponse = client
                                          .Search <ParentTestClass>(s =>
                                                                    s.Query(q =>
                                                                            q.Match(m => m.Field(field => field.Id)
                                                                                    .Query(testClass.Id.ToString())))
                                                                    .Index(index));

                var searchTermResponse = client
                                         .Search <ParentTestClass>(s =>
                                                                   s.Query(q =>
                                                                           q.Term(m => m.Field(field => field.Id)
                                                                                  .Value(testClass.Id.ToString())))
                                                                   .Index(index));

                //ASSERT match response
                Assert.IsTrue(searchMatchResponse.IsValid);
                Assert.AreEqual(1, searchMatchResponse.Documents.Count());
                Assert.AreEqual(testClass.Id, searchMatchResponse.Documents.First().Id);
                Assert.AreEqual(1, searchMatchResponse.Documents.First().Children.Count());
                Assert.AreEqual(testClass.Children.First().Id, searchMatchResponse.Documents.First().Children.First().Id);

                //ASSERT term response
                Assert.IsTrue(searchTermResponse.IsValid);
                Assert.AreEqual(1, searchTermResponse.Documents.Count());
                Assert.AreEqual(testClass.Id, searchTermResponse.Documents.First().Id);
                Assert.AreEqual(1, searchTermResponse.Documents.First().Children.Count());
                Assert.AreEqual(testClass.Children.First().Id, searchTermResponse.Documents.First().Children.First().Id);
            }
            finally
            {
                var deleteIndexResult = client.DeleteIndex(index);
            }
        }
Пример #11
0
        public string GetQuery()
        {
            string sql           = string.Empty;
            string indexName     = IndexName.ToQuota();
            string objectName    = $"{SchemaName.ToQuota()}.{ObjectName.ToQuota()}";
            string fullIndexName = $"{indexName} ON {objectName}";
            string partition     = IsPartitioned ? PartitionNumber.ToString() : "ALL";

            if (IsColumnstore)
            {
                switch (FixType)
                {
                case IndexOp.REBUILD:
                case IndexOp.REBUILD_COLUMNSTORE:
                case IndexOp.REBUILD_COLUMNSTORE_ARCHIVE:
                    DataCompression compression = (FixType == IndexOp.REBUILD_COLUMNSTORE) ? DataCompression.COLUMNSTORE : DataCompression.COLUMNSTORE_ARCHIVE;
                    sql = $"ALTER INDEX {fullIndexName} REBUILD PARTITION = {partition}\n    " +
                          $"WITH (DATA_COMPRESSION = {(FixType == IndexOp.REBUILD ? DataCompression : compression)}, MAXDOP = {Settings.Options.MaxDop});";
                    break;

                case IndexOp.REORGANIZE:
                case IndexOp.REORGANIZE_COMPRESS_ALL_ROW_GROUPS:
                    sql = $"ALTER INDEX {fullIndexName} REORGANIZE PARTITION = {partition}" +
                          $"{(FixType == IndexOp.REORGANIZE_COMPRESS_ALL_ROW_GROUPS ? "\n    WITH (COMPRESS_ALL_ROW_GROUPS = ON)" : "")};";
                    break;
                }
            }
            else
            {
                switch (FixType)
                {
                case IndexOp.REBUILD:
                case IndexOp.REBUILD_ROW:
                case IndexOp.REBUILD_PAGE:
                case IndexOp.REBUILD_NONE:
                case IndexOp.REBUILD_ONLINE:
                case IndexOp.CREATE_INDEX:

                    DataCompression compression;
                    if (FixType == IndexOp.REBUILD_PAGE)
                    {
                        compression = DataCompression.PAGE;
                    }
                    else if (FixType == IndexOp.REBUILD_ROW)
                    {
                        compression = DataCompression.ROW;
                    }
                    else if (FixType == IndexOp.REBUILD_NONE)
                    {
                        compression = DataCompression.NONE;
                    }
                    else if (Settings.Options.DataCompression != DataCompression.DEFAULT && FixType != IndexOp.REBUILD)
                    {
                        compression = Settings.Options.DataCompression;
                    }
                    else
                    {
                        compression = DataCompression;
                    }

                    string onlineRebuild = "OFF";
                    if (FixType == IndexOp.REBUILD_ONLINE || (Settings.Options.Online && IsAllowOnlineRebuild))
                    {
                        if (Settings.Options.WaitAtLowPriority && Settings.ServerInfo.MajorVersion >= ServerVersion.Sql2014)
                        {
                            onlineRebuild = "ON (" +
                                            $"WAIT_AT_LOW_PRIORITY (MAX_DURATION = {Settings.Options.MaxDuration} MINUTES, " +
                                            $"ABORT_AFTER_WAIT = {Settings.Options.AbortAfterWait}))";
                        }
                        else
                        {
                            onlineRebuild = "ON";
                        }
                    }

                    string sqlHeader;
                    if (IndexType == IndexType.MISSING_INDEX)
                    {
                        sqlHeader = $"CREATE NONCLUSTERED INDEX {fullIndexName}\n    ({IndexColumns})\n    "
                                    + (string.IsNullOrEmpty(IncludedColumns) ? "" : $"INCLUDE ({IncludedColumns})\n    ");
                    }
                    else if (IndexType == IndexType.HEAP)
                    {
                        sqlHeader = $"ALTER TABLE {objectName} REBUILD PARTITION = {partition}\n    ";
                    }
                    else
                    {
                        sqlHeader = $"ALTER INDEX {fullIndexName} REBUILD PARTITION = {partition}\n    ";
                    }

                    sql = sqlHeader +
                          "WITH (" +
                          (IndexType == IndexType.HEAP
                      ? ""
                      : $"SORT_IN_TEMPDB = {Settings.Options.SortInTempDb.OnOff()}, ") +
                          (IsPartitioned || IndexType == IndexType.HEAP
                      ? ""
                      : $"PAD_INDEX = {Settings.Options.PadIndex.OnOff()}, ") +
                          (IsPartitioned || Settings.Options.FillFactor == 0
                      ? ""
                      : $"FILLFACTOR = {Settings.Options.FillFactor}, ") +
                          (IsPartitioned || Settings.Options.NoRecompute == NoRecompute.DEFAULT || IndexType == IndexType.HEAP
                      ? ""
                      : $"STATISTICS_NORECOMPUTE = {Settings.Options.NoRecompute}, ") +
                          (!IsAllowCompression
                      ? ""
                      : $"DATA_COMPRESSION = {compression}, ") +
                          $"ONLINE = {onlineRebuild}, " +
                          $"MAXDOP = {Settings.Options.MaxDop});";
                    break;

                case IndexOp.REORGANIZE:
                    sql = $"ALTER INDEX {fullIndexName} REORGANIZE PARTITION = {partition}\n    " +
                          $"WITH (LOB_COMPACTION = {Settings.Options.LobCompaction.OnOff()});";
                    break;

                case IndexOp.DISABLE_INDEX:
                    sql = $"ALTER INDEX {fullIndexName} DISABLE;";
                    break;

                case IndexOp.DROP_INDEX:
                    sql = $"DROP INDEX {fullIndexName};";
                    break;

                case IndexOp.DROP_TABLE:
                    sql = $"DROP TABLE {objectName};";
                    break;

                case IndexOp.UPDATE_STATISTICS_SAMPLE:
                case IndexOp.UPDATE_STATISTICS_RESAMPLE:
                case IndexOp.UPDATE_STATISTICS_FULL:
                    sql = $"UPDATE STATISTICS {objectName} {indexName}\n    " + (
                        FixType == IndexOp.UPDATE_STATISTICS_SAMPLE
                    ? $"WITH SAMPLE {Settings.Options.SampleStatsPercent} PERCENT;"
                    : (FixType == IndexOp.UPDATE_STATISTICS_FULL ? "WITH FULLSCAN;" : "WITH RESAMPLE;")
                        );
                    break;
                }
            }

            return(sql);
        }
Пример #12
0
 public override int GetHashCode()
 {
     using (MD5 md5 = new MD5CryptoServiceProvider())
     {
         return(BitConverter.ToString(md5.ComputeHash(ASCIIEncoding.Default.GetBytes(SchemaName.ToLower() + TableName.ToLower() + IndexName.ToLower()))).GetHashCode());
     }
 }
Пример #13
0
    private string AddConstraintUsingIndex(IMetadata sourceMetadata, IMetadata targetMetadata, IComparerContext context)
    {
        var builder = new StringBuilder();

        if (RelationConstraintType == RelationConstraintType.PrimaryKey || RelationConstraintType == RelationConstraintType.ForeignKey || RelationConstraintType == RelationConstraintType.Unique)
        {
            if (ConstraintName != IndexName && !SqlHelper.HasSystemPrefix(IndexName) || Index.Descending)
            {
                builder
                .AppendLine()
                .Append($"  USING {(Index.Descending ? "DESCENDING" : "ASCENDING")} INDEX {IndexName.AsSqlIndentifier()}");
            }
        }
        return(builder.ToString());
    }
        public void CreatePersonSearchDocumentTest()
        {
            //ARRANGE
            //set up a person

            var dependencyResolver = new DependencyResolverMock();
            var id            = Guid.NewGuid();
            var client        = SearchClientFactory.GetClient();
            var clientFactory = SearchClientFactory.GetClientFactory();

            SearchClientFactory.RegisterDependencies(dependencyResolver);

            //delete person index
            var index = new IndexName {
                Name = String.Format("{0}_{1}", typeof(EsPersonSearch).Name, id).ToLower(), Type = typeof(EsPersonSearch)
            };
            var deleteIndexResult = client.DeleteIndex(index);

            //set up document CRUD controller and create a mock document
            var responseHandler    = new ResponseHandler();
            var indexManager       = new IndexManager(dependencyResolver, clientFactory, responseHandler);
            var documentDispatcher = new DocumentDispatcher(clientFactory, indexManager, responseHandler);
            var documentclient     = new DocumentController(documentDispatcher, indexManager, responseHandler);

            var builder  = new AddPersonContextBuilder();
            var personId = Guid.NewGuid();
            var ev       = new NewPersonAdded(
                new AggregateId(personId),
                new CQRS.CorrelationId(personId),
                null,
                1,
                1,
                1,
                new PersonName
            {
                FirstName = "John",
                LastName  = "Doe"
            },
                null);

            var context = builder.BuildContext(ev);

            try
            {
                //create person document
                documentclient.UpsertDocument(context);
                Thread.Sleep(1000);

                var document = client.Get <EsPersonSearch>(personId, d => d.Index(index));

                var personName = new PersonName
                {
                    FirstName = "John1",
                    LastName  = "Doe1"
                };

                var builder1 = new AddPossitionContexttBuilder();
                var ev1      = new NewPositionAdded(
                    new AggregateId(personId),
                    null,
                    new CQRS.CorrelationId(personId),
                    personId,
                    Guid.NewGuid(),
                    null,
                    1,
                    1,
                    1,
                    personName,
                    "TestOrganisation");

                var newPossitionAdded = builder1.BuildContext(ev1);
                context = builder1.BuildContext(ev1);

                documentclient.UpsertDocument(context);
                Thread.Sleep(1000);

                document = client.Get <EsPersonSearch>(personId, d => d.Index(index));

                var builder2 = new PersonNameEditedContextBuilder();
                var ev2      = new NameEdited(
                    new AggregateId(personId),
                    1,
                    new CQRS.CorrelationId(personId),
                    null,
                    personName,
                    1);


                context = builder2.BuildContext(ev2);


                documentclient.UpsertDocument(context);
                Thread.Sleep(1000);

                document = client.Get <EsPersonSearch>(personId, d => d.Index(index));
            }
            finally
            {
                client.DeleteIndex(index);
            }
        }
        private void CreateIndex()
        {
            var postIndex = IndexName.From <Post>();

            #region Default Analyzer
            //var aaa = elasticClient.Indices.UpdateSettings(postIndex, p => p
            //    .IndexSettings(p => p
            //        .Analysis(p => p
            //            .Analyzers(p => p
            //                .UserDefined("default", new SimpleAnalyzer())
            //            )
            //        )
            //    )
            //);
            //Request:
            //PUT http://localhost:9200/my-post-index/_settings?pretty=true&error_trace=true
            //{
            //  "analysis": {
            //    "analyzer": {
            //      "default": {
            //        "type": "simple"
            //      }
            //    }
            //  }
            //}

            //var bbb = elasticClient.Indices.Create(postIndex, p => p
            //    .Settings(p => p
            //        .Analysis(p => p
            //            .Analyzers(p => p
            //                .UserDefined("default", new SimpleAnalyzer())
            //            )
            //        )
            //    )
            //);
            //Request:
            //PUT http://localhost:9200/my-post-index?pretty=true&error_trace=true
            //{
            //  "settings": {
            //    "analysis": {
            //      "analyzer": {
            //        "default": {
            //          "type": "simple"
            //        }
            //      }
            //    }
            //  }
            //}
            #endregion

            //### Delete
            var deleteIndexResponse = elasticClient.Indices.Delete(postIndex);

            //### Create Index
            var stopwordsPath = Path.Combine(Directory.GetCurrentDirectory(), "stopwords.txt");

            //var stopwords = File.ReadAllLines(stopwordsPath).Select(p => p.Trim());
            var stopwords = new[] {
                "جامع",
                "آرام",
                "میرود",
                "کردند",
                "123"
            };

            #region Persian & Arabic Analyzer/Normalizer
            //Persian Chars
            //Normalizer: https://github.com/apache/lucenenet/blob/master/src/Lucene.Net.Analysis.Common/Analysis/Fa/PersianNormalizer.cs
            //YEH_FARSI	        (char)1740 == '\u06CC'	    'ی'
            //YEH		        (char)1610 == '\u064A'	    'ي'
            //YEH_BARREE	    (char)1746 == '\u06D2'	    'ے'
            //HEH (farsi)	    (char)1607 == '\u0647'	    'ه'
            //HEH_YEH		    (char)1728 == '\u06C0'	    'ۀ'
            //HEH_GOAL	        (char)1729 == '\u06C1'	    'ہ'
            //KEHEH             (char)1705 == '\u06A9'	    'ک'
            //KAF		        (char)1603 == '\u0643'	    'ك'
            //HAMZA_ABOVE       (char)1620 == '\u0654'	    'ٔ'
            //ZERO_SPACE        (char)8204 == '\u200C'      '‌'
            //NORMAL_SPACE      (char)32   == '\u0020'      ' '

            //Persian Fixing
            //YEH		        "\\u064A=>\\u06CC"          'ي' => 'ی'
            //YEH_BARREE	    "\\u06D2=>\\u06CC"          'ے' => 'ی'
            //KAF		        "\\u0643=>\\u06A9"          'ك' => 'ک'
            //HEH_YEH	        "\\u06C0=>\\u0647"          'ۀ' => 'ه'
            //HEH_GOAL	        "\\u06C1=>\\u0647"          'ہ' => 'ه'
            //HAMZA_ABOVE       REMOVE "\\u0654=>"          'ٔ'

            //Arabic Chars (except persians)
            //Normalizer: https://github.com/apache/lucenenet/blob/master/src/Lucene.Net.Analysis.Common/Analysis/Ar/ArabicNormalizer.cs
            //ALEF              (char)1575 == '\u0627'      'ا'
            //ALEF_MADDA        (char)1570 == '\u0622'      'آ'
            //ALEF_HAMZA_ABOVE  (char)1571 == '\u0623'      'أ'
            //ALEF_HAMZA_BELOW  (char)1573 == '\u0625'      'إ'
            //DOTLESS_YEH       (char)1609 == '\u0649'      'ى'
            //TEH_MARBUTA       (char)1577 == '\u0629'      'ة'
            //TATWEEL           (char)1600 == '\u0640'      'ـ' (KhateTire)
            //FATHA             (char)1614 == '\u064E'      'َ' (Fathe)
            //FATHATAN          (char)1611 == '\u064B'      'ً' (TanvinFathe)
            //DAMMA             (char)1615 == '\u064F'      'ُ' (Zamme)
            //DAMMATAN          (char)1612 == '\u064C'      'ٌ' (TanvinZamme)
            //KASRA             (char)1616 == '\u0650'      'ِ' (Kasre)
            //KASRATAN          (char)1613 == '\u064D'      'ٍ' (TanvinKasre)
            //SHADDA            (char)1617 == '\u0651'      'ّ' (Tashdid)
            //SUKUN             (char)1618 == '\u0652'      'ْ' (Sokun)

            //Arabic Fixing
            //ALEF_MADDA        "\\u0622=>\\u0627"          'آ' => 'ا'
            //ALEF_HAMZA_ABOVE  "\\u0623=>\\u0627"          'أ' => 'ا'
            //ALEF_HAMZA_BELOW  "\\u0625=>\\u0627"          'إ' => 'ا'
            //DOTLESS_YEH       "\\u0649=>\\u06CC"          'ى' => 'ی'  (original normalizer replaces with \u064A 'ي')
            //TEH_MARBUTA       "\\u0629=>\\u0647"          'ة' => 'ه'
            //TATWEEL           REMOVE "\\u0640=>"          'ـ' (KhateTire)
            //FATHA             REMOVE "\\u064E=>"          'َ' (Fathe)
            //FATHATAN          REMOVE "\\u064B=>"          'ً' (TanvinFathe)
            //DAMMA             REMOVE "\\u064F=>"          'ُ' (Zamme)
            //DAMMATAN          REMOVE "\\u064C=>"          'ٌ' (TanvinZamme)
            //KASRA             REMOVE "\\u0650=>"          'ِ' (Kasre)
            //KASRATAN          REMOVE "\\u064D=>"          'ٍ' (TanvinKasre)
            //SHADDA            REMOVE "\\u0651=>"          'ّ' (Tashdid)
            //SUKUN             REMOVE "\\u0652=>"          'ْ' (Sokun)

            //Arab Ameri Chars
            //Normalizer: https://github.com/SalmanAA/Lucene.Net.Analysis.Fa/blob/master/Lucene.Net.Analysis.Fa/PersianNormalizer.cs
            //Stemer    : https://github.com/SalmanAA/Lucene.Net.Analysis.Fa/blob/master/Lucene.Net.Analysis.Fa/PersianStemmer.cs
            //HAMZE_JODA        (char)1569 == '\u0621'      'ء' (HamzeJoda)

            //Arab Ameri Fixing
            //HAMZE_JODA        REMOVE "\\u0621=>"          'ء' (HamzeJoda)



            //var createIndexResponse = elasticClient.Indices.Create(postIndex, p => p
            //    .Settings(p => p
            //        .Analysis(p => p
            //            .CharFilters(p => p
            //                //https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-mapping-charfilter.html
            //                .Mapping("mapping_filter", p => p
            //                    .Mappings(
            //                        "\\u200C=>\\u0020"//, //Fix ZERO_SPACE
            //                                          //"\\u064A=>\\u06CC", //Fix YEH
            //                                          //"\\u06D2=>\\u06CC", //Fix YEH_BARREE
            //                                          //"\\u0649=>\\u06CC", //Fix DOTLESS_YEH
            //                                          //"\\u0643=>\\u06A9", //Fix KAF
            //                                          //"\\u06C0=>\\u0647", //Fix HEH_YEH
            //                                          //"\\u06C1=>\\u0647", //Fix HEH_GOAL
            //                                          //"\\u0629=>\\u0647", //Fix TEH_MARBUTA
            //                                          //"\\u0622=>\\u0627", //Fix ALEF_MADDA
            //                                          //"\\u0623=>\\u0627", //Fix ALEF_HAMZA_ABOVE
            //                                          //"\\u0625=>\\u0627", //Fix ALEF_HAMZA_BELOW
            //                                          //"\\u0654=>",        //Remove HAMZA_ABOVE
            //                                          //"\\u0640=>",        //Remove TATWEEL
            //                                          //"\\u064E=>",        //Remove FATHA
            //                                          //"\\u064B=>",        //Remove FATHATAN
            //                                          //"\\u064F=>",        //Remove DAMMA
            //                                          //"\\u064C=>",        //Remove DAMMATAN
            //                                          //"\\u0650=>",        //Remove KASRA
            //                                          //"\\u064D=>",        //Remove KASRATAN
            //                                          //"\\u0651=>",        //Remove SHADDA
            //                                          //"\\u0652=>"         //Remove SUKUN
            //                                          //"\\u0621=>"         //Remove HAMZE_JODA
            //                    )
            //                )
            //            )
            //            .TokenFilters(p => p
            //                //https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-stop-tokenfilter.html
            //                .Stop("persian_stop", p => p
            //                    .StopWords(stopwords)
            //                    .RemoveTrailing()
            //                //.IgnoreCase()
            //                )
            //                .PatternReplace("fix-YEH", p => p.Pattern("\u064A").Replacement("\u06CC"))
            //                .PatternReplace("fix-YEH_BARREE", p => p.Pattern("\u06D2").Replacement("\u06CC"))
            //                .PatternReplace("fix-DOTLESS_YEH", p => p.Pattern("\u0649").Replacement("\u06CC"))
            //                .PatternReplace("fix-KAF", p => p.Pattern("\u0643").Replacement("\u06A9"))
            //                .PatternReplace("fix-HEH_YEH", p => p.Pattern("\u06C0").Replacement("\u0647"))
            //                .PatternReplace("fix-HEH_GOAL", p => p.Pattern("\u06C1").Replacement("\u0647"))
            //                .PatternReplace("fix-TEH_MARBUTA", p => p.Pattern("\u0629").Replacement("\u0647"))
            //                .PatternReplace("fix-ALEF_MADDA", p => p.Pattern("\u0622").Replacement("\u0627"))
            //                .PatternReplace("fix-ALEF_HAMZA_ABOVE", p => p.Pattern("\u0623").Replacement("\u0627"))
            //                .PatternReplace("fix-ALEF_HAMZA_BELOW", p => p.Pattern("\u0625").Replacement("\u0627"))
            //                .PatternReplace("remove-HAMZA_ABOVE", p => p.Pattern("\u0654").Replacement(string.Empty))
            //                .PatternReplace("remove-TATWEEL", p => p.Pattern("\u0640").Replacement(string.Empty))
            //                .PatternReplace("remove-FATHA", p => p.Pattern("\u064E").Replacement(string.Empty))
            //                .PatternReplace("remove-FATHATAN", p => p.Pattern("\u064B").Replacement(string.Empty))
            //                .PatternReplace("remove-DAMMA", p => p.Pattern("\u064F").Replacement(string.Empty))
            //                .PatternReplace("remove-DAMMATAN", p => p.Pattern("\u064C").Replacement(string.Empty))
            //                .PatternReplace("remove-KASRA", p => p.Pattern("\u0650").Replacement(string.Empty))
            //                .PatternReplace("remove-KASRATAN", p => p.Pattern("\u064D").Replacement(string.Empty))
            //                .PatternReplace("remove-SHADDA", p => p.Pattern("\u0651").Replacement(string.Empty))
            //                .PatternReplace("remove-SUKUN", p => p.Pattern("\u0652").Replacement(string.Empty))
            //                .PatternReplace("remove-HAMZE_JODA", p => p.Pattern("\u0621").Replacement(string.Empty))
            //            )
            //            .Analyzers(p => p
            //                .Custom("persian_analyzer", p => p
            //                    .Tokenizer("standard") //https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-standard-tokenizer.html
            //                    .CharFilters(
            //                        "html_strip", //https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-htmlstrip-charfilter.html
            //                        "mapping_filter"
            //                    )
            //                    .Filters(
            //                        "lowercase", //https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-lowercase-tokenfilter.html
            //                        "decimal_digit", //https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-decimal-digit-tokenfilter.html
            //                        "persian_stop",

            //                        //"arabic_normalization", //https://lucene.apache.org/core/8_8_0/analyzers-common/org/apache/lucene/analysis/ar/ArabicNormalizer.html
            //                        //"persian_normalization", //https://lucene.apache.org/core/8_8_0/analyzers-common/org/apache/lucene/analysis/fa/PersianNormalizer.html
            //                        "fix-YEH",
            //                        "fix-YEH_BARREE",
            //                        "fix-DOTLESS_YEH",
            //                        "fix-KAF",
            //                        "fix-HEH_YEH",
            //                        "fix-HEH_GOAL",
            //                        "fix-TEH_MARBUTA",
            //                        "fix-ALEF_MADDA",
            //                        "fix-ALEF_HAMZA_ABOVE",
            //                        "fix-ALEF_HAMZA_BELOW",
            //                        "remove-HAMZA_ABOVE",
            //                        "remove-TATWEEL",
            //                        "remove-FATHA",
            //                        "remove-FATHATAN",
            //                        "remove-DAMMA",
            //                        "remove-DAMMATAN",
            //                        "remove-KASRA",
            //                        "remove-KASRATAN",
            //                        "remove-SHADDA",
            //                        "remove-SUKUN",
            //                        "remove-SUKUN",
            //                        "remove-HAMZE_JODA",

            //                        "persian_stop" //remove stopwords before and after normalizations because of ('آ' => 'ا')
            //                    )
            //                )
            //            )
            //        )
            //    )
            //    .Map<Post>(p => p
            //        .AutoMap()
            //        .Properties(p => p
            //            //.Number(p => p.Name(p => p.Id))
            //            .Text(p => p
            //                .Name(p => p.Title)
            //                .Analyzer("persian_analyzer")
            //            )
            //            .Text(p => p
            //                .Name(p => p.Body)
            //                .Analyzer("persian_analyzer")
            //            //.SearchAnalyzer("persian_analyzer")
            //            //.Boost(1.5)
            //            //.Store(true)
            //            //.Index(true)
            //            //.Norms(true)
            //            //.IndexPhrases(true)
            //            //.IndexOptions(IndexOptions.Offsets)
            //            //.TermVector(TermVectorOption.WithPositionsOffsetsPayloads)
            //            )
            //        )
            //    )
            //);
            #endregion

            var createIndexResponse = elasticClient.Indices.Create(postIndex, p => p
                                                                   .Settings(p => p
                                                                             .Analysis(p => p
                                                                                       .CharFilters(p => p
                                                                                                    .Mapping("mapping_filter", p => p
                                                                                                             .Mappings(
                                                                                                                 "\\u200C=>\\u0020" //Fix ZERO_SPACE
                                                                                                                 )
                                                                                                             )
                                                                                                    )
                                                                                       .TokenFilters(p => p
                                                                                                     .Stop("persian_stop", p => p
                                                                                                           .StopWords(new StopWords("_persian_"))
                                                                                                           .RemoveTrailing()
                                                                                                           )
                                                                                                     )
                                                                                       .Analyzers(p => p
                                                                                                  .Custom("persian_analyzer", p => p
                                                                                                          .Tokenizer("standard")
                                                                                                          .CharFilters(
                                                                                                              "html_strip",
                                                                                                              "mapping_filter"
                                                                                                              )
                                                                                                          .Filters(
                                                                                                              "lowercase",
                                                                                                              "decimal_digit",
                                                                                                              "arabic_normalization",
                                                                                                              "persian_normalization",
                                                                                                              "persian_stop"
                                                                                                              )
                                                                                                          )
                                                                                                  )
                                                                                       )
                                                                             )
                                                                   .Map <Post>(p => p
                                                                               .AutoMap()
                                                                               .Properties(p => p
                                                                                           .Text(p => p
                                                                                                 .Name(p => p.Title)
                                                                                                 .Analyzer("persian_analyzer")
                                                                                                 //.Boost(1.5)
                                                                                                 )
                                                                                           .Text(p => p
                                                                                                 .Name(p => p.Body)
                                                                                                 .Analyzer("persian_analyzer")
                                                                                                 //.Boost(1.0)
                                                                                                 //.Store(true)
                                                                                                 //.Index(true)
                                                                                                 //.Norms(true)
                                                                                                 //.IndexPhrases(true)
                                                                                                 //.IndexOptions(IndexOptions.Offsets)
                                                                                                 //.TermVector(TermVectorOption.WithPositionsOffsetsPayloads)
                                                                                                 )
                                                                                           )
                                                                               )
                                                                   );

            //Request:
            //PUT /my-post-index?pretty=true&error_trace=true
            //{
            //  "mappings": {
            //    "properties": {
            //      "id": {
            //        "type": "integer"
            //      },
            //      "title": {
            //        "analyzer": "persian_analyzer",
            //        "boost": 1.5,
            //        "type": "text"
            //      },
            //      "body": {
            //        "analyzer": "persian_analyzer",
            //        "boost": 1.0,
            //        "type": "text"
            //      }
            //    }
            //  },
            //  "settings": {
            //    "analysis": {
            //      "analyzer": {
            //        "persian_analyzer": {
            //          "char_filter": [
            //            "html_strip",
            //            "mapping_filter"
            //          ],
            //          "filter": [
            //            "lowercase",
            //            "decimal_digit",
            //            "arabic_normalization",
            //            "persian_normalization",
            //            "persian_stop"
            //          ],
            //          "tokenizer": "standard",
            //          "type": "custom"
            //        }
            //      },
            //      "char_filter": {
            //        "mapping_filter": {
            //          "mappings": [
            //            "\\u200C=>\\u0020"
            //          ],
            //          "type": "mapping"
            //        }
            //      },
            //      "filter": {
            //        "persian_stop": {
            //          "remove_trailing": true,
            //          "stopwords": "_persian_",
            //          "type": "stop"
            //        }
            //      }
            //    }
            //  }
            //}
        }
        [U] public void IndexdNotEq()
        {
            IndexName t1 = typeof(Project), t2 = typeof(CommitActivity);

            (t1 != t2).ShouldBeTrue(t2);
        }
Пример #17
0
		public AnalyzeRequest(IndexName indices, string textToAnalyze)
			:this(indices)
		{
			this.Text = new[] { textToAnalyze };
		}
Пример #18
0
 /// <summary>
 /// <c>POST</c> request to the <c>ccr.forget_follower</c> API, read more about this API online:
 /// <para></para>
 /// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-post-forget-follower.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-post-forget-follower.html</a>
 /// </summary>
 public ForgetFollowerIndexResponse ForgetFollowerIndex(IndexName index, Func <ForgetFollowerIndexDescriptor, IForgetFollowerIndexRequest> selector) => ForgetFollowerIndex(selector.InvokeOrDefault(new ForgetFollowerIndexDescriptor(index: index)));
Пример #19
0
 /// <summary>
 /// <c>POST</c> request to the <c>ccr.forget_follower</c> API, read more about this API online:
 /// <para></para>
 /// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-post-forget-follower.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-post-forget-follower.html</a>
 /// </summary>
 public Task <ForgetFollowerIndexResponse> ForgetFollowerIndexAsync(IndexName index, Func <ForgetFollowerIndexDescriptor, IForgetFollowerIndexRequest> selector, CancellationToken ct = default) => ForgetFollowerIndexAsync(selector.InvokeOrDefault(new ForgetFollowerIndexDescriptor(index: index)), ct);
Пример #20
0
 /// <summary>
 /// <c>POST</c> request to the <c>ccr.pause_follow</c> API, read more about this API online:
 /// <para></para>
 /// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-post-pause-follow.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-post-pause-follow.html</a>
 /// </summary>
 public PauseFollowIndexResponse PauseFollowIndex(IndexName index, Func <PauseFollowIndexDescriptor, IPauseFollowIndexRequest> selector = null) => PauseFollowIndex(selector.InvokeOrDefault(new PauseFollowIndexDescriptor(index: index)));
Пример #21
0
 /// <summary>
 /// <c>POST</c> request to the <c>ilm.move_to_step</c> API, read more about this API online:
 /// <para></para>
 /// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-move-to-step.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-move-to-step.html</a>
 /// </summary>
 public MoveToStepResponse MoveToStep(IndexName index, Func <MoveToStepDescriptor, IMoveToStepRequest> selector = null) => MoveToStep(selector.InvokeOrDefault(new MoveToStepDescriptor(index: index)));
Пример #22
0
 /// <summary>
 /// <c>POST</c> request to the <c>ccr.resume_follow</c> API, read more about this API online:
 /// <para></para>
 /// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-post-resume-follow.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-post-resume-follow.html</a>
 /// </summary>
 public ResumeFollowIndexResponse ResumeFollowIndex(IndexName index, Func <ResumeFollowIndexDescriptor, IResumeFollowIndexRequest> selector = null) => ResumeFollowIndex(selector.InvokeOrDefault(new ResumeFollowIndexDescriptor(index: index)));
Пример #23
0
 /// <summary>
 /// <c>POST</c> request to the <c>ilm.retry</c> API, read more about this API online:
 /// <para></para>
 /// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-retry-policy.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-retry-policy.html</a>
 /// </summary>
 public RetryIlmResponse Retry(IndexName index, Func <RetryIlmDescriptor, IRetryIlmRequest> selector = null) => Retry(selector.InvokeOrDefault(new RetryIlmDescriptor(index: index)));
Пример #24
0
 /// <summary>
 /// <c>POST</c> request to the <c>ccr.unfollow</c> API, read more about this API online:
 /// <para></para>
 /// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-post-unfollow.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-post-unfollow.html</a>
 /// </summary>
 public UnfollowIndexResponse UnfollowIndex(IndexName index, Func <UnfollowIndexDescriptor, IUnfollowIndexRequest> selector = null) => UnfollowIndex(selector.InvokeOrDefault(new UnfollowIndexDescriptor(index: index)));
Пример #25
0
 /// <summary>
 /// <c>GET</c> request to the <c>ilm.explain_lifecycle</c> API, read more about this API online:
 /// <para></para>
 /// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-explain-lifecycle.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-explain-lifecycle.html</a>
 /// </summary>
 public ExplainLifecycleResponse ExplainLifecycle(IndexName index, Func <ExplainLifecycleDescriptor, IExplainLifecycleRequest> selector = null) => ExplainLifecycle(selector.InvokeOrDefault(new ExplainLifecycleDescriptor(index: index)));
Пример #26
0
 /// <summary>
 /// <c>POST</c> request to the <c>ccr.unfollow</c> API, read more about this API online:
 /// <para></para>
 /// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-post-unfollow.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-post-unfollow.html</a>
 /// </summary>
 public Task <UnfollowIndexResponse> UnfollowIndexAsync(IndexName index, Func <UnfollowIndexDescriptor, IUnfollowIndexRequest> selector = null, CancellationToken ct = default) => UnfollowIndexAsync(selector.InvokeOrDefault(new UnfollowIndexDescriptor(index: index)), ct);
		public IShrinkIndexResponse ShrinkIndex(IndexName source, IndexName target, Func<ShrinkIndexDescriptor, IShrinkIndexRequest> selector = null) =>
			this.ShrinkIndex(selector.InvokeOrDefault(new ShrinkIndexDescriptor(source, target)));
Пример #28
0
 /// <summary>
 /// <c>PUT</c> request to the <c>ccr.follow</c> API, read more about this API online:
 /// <para></para>
 /// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-put-follow.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-put-follow.html</a>
 /// </summary>
 public CreateFollowIndexResponse CreateFollowIndex(IndexName index, Func <CreateFollowIndexDescriptor, ICreateFollowIndexRequest> selector) => CreateFollowIndex(selector.InvokeOrDefault(new CreateFollowIndexDescriptor(index: index)));
Пример #29
0
        [U] public async Task Urls()
        {
            var name  = "name-of-perc";
            var index = "indexx";

            await DELETE($"/{index}/.percolator/{name}")
            .Fluent(c => c.UnregisterPercolator <Project>(name, s => s.Index(index)))
            .Request(c => c.UnregisterPercolator(new UnregisterPercolatorRequest(index, name)))
            .FluentAsync(c => c.UnregisterPercolatorAsync <Project>(name, s => s.Index(index)))
            .RequestAsync(c => c.UnregisterPercolatorAsync(new UnregisterPercolatorRequest(index, name)))
            ;

            await DELETE($"/project/.percolator/{name}")
            .Fluent(c => c.UnregisterPercolator <Project>(name))
            .Request(c => c.UnregisterPercolator(new UnregisterPercolatorRequest(typeof(Project), name)))
            .FluentAsync(c => c.UnregisterPercolatorAsync <Project>(name))
            .RequestAsync(c => c.UnregisterPercolatorAsync(new UnregisterPercolatorRequest(IndexName.From <Project>(), name)))
            ;
        }
Пример #30
0
 /// <summary>
 /// <c>PUT</c> request to the <c>ccr.follow</c> API, read more about this API online:
 /// <para></para>
 /// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-put-follow.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-put-follow.html</a>
 /// </summary>
 public Task <CreateFollowIndexResponse> CreateFollowIndexAsync(IndexName index, Func <CreateFollowIndexDescriptor, ICreateFollowIndexRequest> selector, CancellationToken ct = default) => CreateFollowIndexAsync(selector.InvokeOrDefault(new CreateFollowIndexDescriptor(index: index)), ct);
        [U] public void IndexdEq()
        {
            IndexName t1 = typeof(Project), t2 = typeof(Project);

            (t1 == t2).ShouldBeTrue(t2);
        }
Пример #32
0
 public ElasticConnection(IndexName index = null)
 {
     this.Index = index;
 }
Пример #33
0
 public RoyalSeeder(IElasticClient client, IndexName index)
 {
     _client = client;
     _index  = index;
 }
 /// <summary>
 /// <c>GET</c> request to the <c>rollup.get_rollup_index_caps</c> API, read more about this API online:
 /// <para></para>
 /// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/rollup-get-rollup-index-caps.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/rollup-get-rollup-index-caps.html</a>
 /// </summary>
 public GetRollupIndexCapabilitiesResponse GetIndexCapabilities(IndexName index, Func <GetRollupIndexCapabilitiesDescriptor, IGetRollupIndexCapabilitiesRequest> selector = null) => GetIndexCapabilities(selector.InvokeOrDefault(new GetRollupIndexCapabilitiesDescriptor(index: index)));
Пример #35
0
 public ITableIndex GetIndex(IndexName indexName)
 {
     ITableIndex index;
     if (!indexes.TryGetValue(indexName, out index))
         return null;
     return index;
 }
 /// <summary>
 /// <c>GET</c> request to the <c>rollup.get_rollup_index_caps</c> API, read more about this API online:
 /// <para></para>
 /// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/rollup-get-rollup-index-caps.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/rollup-get-rollup-index-caps.html</a>
 /// </summary>
 public Task <GetRollupIndexCapabilitiesResponse> GetIndexCapabilitiesAsync(IndexName index, Func <GetRollupIndexCapabilitiesDescriptor, IGetRollupIndexCapabilitiesRequest> selector = null, CancellationToken ct = default) => GetIndexCapabilitiesAsync(selector.InvokeOrDefault(new GetRollupIndexCapabilitiesDescriptor(index: index)), ct);
Пример #37
0
 public void DeleteIndex(IndexName indexName)
 {
     indexes.Remove(indexName);
 }
Пример #38
0
        public string GetQuery()
        {
            string          sql         = string.Empty;
            string          indexName   = IndexName.ToQuota();
            string          schemaName  = SchemaName.ToQuota();
            string          objectName  = ObjectName.ToQuota();
            string          partition   = IsPartitioned ? PartitionNumber.ToString() : "ALL";
            DataCompression compression = DataCompression;

            if (IsColumnstore)
            {
                if (FixType == IndexOp.RebuildColumnstore)
                {
                    compression = DataCompression.Columnstore;
                }

                if (FixType == IndexOp.RebuildColumnstoreArchive)
                {
                    compression = DataCompression.ColumnstoreArchive;
                }

                switch (FixType)
                {
                case IndexOp.Rebuild:
                case IndexOp.RebuildColumnstore:
                case IndexOp.RebuildColumnstoreArchive:
                    sql = $"ALTER INDEX [{indexName}]\n    " +
                          $"ON [{schemaName}].[{objectName}] REBUILD PARTITION = {partition}\n    " +
                          $"WITH (DATA_COMPRESSION = {compression.ToDescription()}, MAXDOP = {Settings.Options.MaxDop});";
                    break;

                case IndexOp.Reorganize:
                    sql = $"ALTER INDEX [{indexName}]\n    " +
                          $"ON [{schemaName}].[{objectName}] REORGANIZE PARTITION = {partition};";
                    break;

                case IndexOp.ReorganizeCompressAllRowGroup:
                    sql = $"ALTER INDEX [{indexName}]\n    " +
                          $"ON [{schemaName}].[{objectName}] REORGANIZE PARTITION = {partition}\n    " +
                          "WITH (COMPRESS_ALL_ROW_GROUPS = ON);";
                    break;
                }
            }
            else
            {
                if (FixType == IndexOp.RebuildPage)
                {
                    compression = DataCompression.Page;
                }
                else if (FixType == IndexOp.RebuildRow)
                {
                    compression = DataCompression.Row;
                }
                else if (FixType == IndexOp.RebuildNone)
                {
                    compression = DataCompression.None;
                }

                switch (FixType)
                {
                case IndexOp.CreateIndex:
                    bool isCreateOnline = Settings.ServerInfo.MajorVersion > Server.Sql2008 &&
                                          Settings.ServerInfo.IsOnlineRebuildAvailable &&
                                          Settings.Options.Online;

                    sql = $"CREATE NONCLUSTERED INDEX [{indexName}]\n" +
                          $"ON [{schemaName}].[{objectName}] ({IndexColumns})\n" +
                          (string.IsNullOrEmpty(IncludedColumns) ? "" : $"INCLUDE({IncludedColumns})\n") +
                          $"WITH (SORT_IN_TEMPDB = {(Settings.Options.SortInTempDb ? Options.ON : Options.OFF)}, " +
                          $"ONLINE = {(isCreateOnline ? Options.ON : Options.OFF)}, " +
                          (Settings.Options.FillFactor.IsBetween(1, 100)
                            ? $"FILLFACTOR = {Settings.Options.FillFactor}, "
                            : ""
                          ) +
                          (Settings.Options.DataCompression == Options.DEFAULT
                            ? ""
                            : $"DATA_COMPRESSION = {Settings.Options.DataCompression}, "
                          ) +
                          (Settings.Options.NoRecompute == Options.DEFAULT
                            ? ""
                            : $"STATISTICS_NORECOMPUTE = {Settings.Options.NoRecompute}, "
                          ) +
                          $"MAXDOP = {Settings.Options.MaxDop});";
                    break;

                case IndexOp.Rebuild:
                case IndexOp.RebuildPage:
                case IndexOp.RebuildRow:
                case IndexOp.RebuildNone:
                case IndexOp.RebuildOnline:
                case IndexOp.RebuildFillFactorZero:
                    if (IndexType == IndexType.Heap)
                    {
                        sql = $"ALTER TABLE [{schemaName}].[{objectName}] REBUILD PARTITION = {partition}\n    " +
                              $"WITH (DATA_COMPRESSION = {compression.ToDescription()}, MAXDOP = {Settings.Options.MaxDop});";
                    }
                    else
                    {
                        string onlineRebuild = "OFF";
                        if (FixType == IndexOp.RebuildOnline)
                        {
                            if (Settings.Options.WaitAtLowPriority && Settings.ServerInfo.MajorVersion >= Server.Sql2014)
                            {
                                onlineRebuild = $"ON (" +
                                                $"WAIT_AT_LOW_PRIORITY(MAX_DURATION = {Settings.Options.MaxDuration} MINUTES, " +
                                                $"ABORT_AFTER_WAIT = {Settings.Options.AbortAfterWait}))";
                            }
                            else
                            {
                                onlineRebuild = Options.ON;
                            }
                        }

                        sql = $"ALTER INDEX [{indexName}]\n    " +
                              $"ON [{schemaName}].[{objectName}] REBUILD PARTITION = {partition}\n    " +
                              $"WITH (SORT_IN_TEMPDB = {(Settings.Options.SortInTempDb ? Options.ON : Options.OFF)}, " +
                              $"ONLINE = {onlineRebuild}, " +
                              (Settings.Options.NoRecompute == Options.DEFAULT
                            ? ""
                            : $"STATISTICS_NORECOMPUTE = {Settings.Options.NoRecompute}, "
                              ) +
                              (FixType == IndexOp.RebuildFillFactorZero
                            ? "FILLFACTOR = 100, "
                            : (Settings.Options.FillFactor.IsBetween(1, 100)
                                  ? $"FILLFACTOR = {Settings.Options.FillFactor}, "
                                  : ""
                               )
                              ) +
                              $"DATA_COMPRESSION = {compression.ToDescription()}, " +
                              $"MAXDOP = {Settings.Options.MaxDop});";
                    }
                    break;

                case IndexOp.Reorganize:
                    sql = $"ALTER INDEX [{indexName}]\n    " +
                          $"ON [{schemaName}].[{objectName}] REORGANIZE PARTITION = {partition}\n    " +
                          $"WITH (LOB_COMPACTION = {(Settings.Options.LobCompaction ? Options.ON : Options.OFF)});";
                    break;

                case IndexOp.Disable:
                    sql = $"ALTER INDEX [{indexName}] ON [{schemaName}].[{objectName}] DISABLE;";
                    break;

                case IndexOp.Drop:
                    sql = $"DROP INDEX [{indexName}] ON [{schemaName}].[{objectName}];";
                    break;

                case IndexOp.UpdateStatsSample:
                case IndexOp.UpdateStatsResample:
                case IndexOp.UpdateStatsFull:
                    sql = $"UPDATE STATISTICS [{schemaName}].[{objectName}] [{indexName}]\n    " + (
                        FixType == IndexOp.UpdateStatsSample
                    ? $"WITH SAMPLE {Settings.Options.SampleStatsPercent} PERCENT;"
                    : (FixType == IndexOp.UpdateStatsFull ? "WITH FULLSCAN;" : "WITH RESAMPLE;")
                        );
                    break;
                }
            }

            return(sql);
        }
		/// <inheritdoc/>
		public Task<IIndicesOperationResponse> CreateIndexAsync(IndexName index, Func<CreateIndexDescriptor, ICreateIndexRequest> selector = null) => 
			this.CreateIndexAsync(selector.InvokeOrDefault(new CreateIndexDescriptor(index)));
		/// <inheritdoc/>
		public ICreateIndexResponse CreateIndex(IndexName index, Func<CreateIndexDescriptor, ICreateIndexRequest> selector = null) =>
			this.CreateIndex(selector.InvokeOrDefault(new CreateIndexDescriptor(index)));