/// <summary>
        /// Search for <c>Knowledge Article</c>.
        /// <para>
        /// For more information look at
        /// <c>By Fulltext</c> : https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.fulltextsearchknowledgearticlerequest.aspx
        /// </para>
        /// </summary>
        /// <param name="searchType"><see cref="SearchTypeCode"/></param>
        /// <param name="query">
        /// Query criteria to find <c>Knowledge Article</c> with specified keyword.
        /// This parameter supports <c>QueryExpression</c> and <c>FetchXml</c>.
        /// <para>
        /// Please note that <see cref="PagingInfo"/> data must be defined in this query.
        /// </para>
        /// </param>
        /// <param name="searchText">Text to search for in <c>Knowledge Article</c> data</param>
        /// <param name="useInflection">Indicates whether to use inflectional stem matching when searching for knowledge base articles with a specified body text</param>
        /// <param name="removeDuplicates">
        /// Indicates whether to remove multiple versions of the same knowledge article in search results.
        /// Default value is <c>true</c>.
        /// </param>
        /// <param name="stateCode">
        /// State of the knowledge articles to filter the search results.
        /// Default value is <c>-1</c> (for all data). For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.fulltextsearchknowledgearticlerequest.statecode.aspx
        /// </param>
        /// <returns>
        /// <see cref="EntityCollection"/> for <c>Article</c> data.
        /// </returns>
        public EntityCollection Search(SearchTypeCode searchType, QueryBase query, string searchText, bool useInflection, bool removeDuplicates = true, int stateCode = -1)
        {
            ExceptionThrow.IfNull(query, "query");
            ExceptionThrow.IfNullOrEmpty(searchText, "searchText");

            if (query is QueryExpression)
            {
                ExceptionThrow.IfNullOrEmpty(((QueryExpression)query).EntityName, "QueryExpression.EntityName");
                ExceptionThrow.IfNotExpectedValue(((QueryExpression)query).EntityName.ToLower(), "QueryExpression.EntityName", this.EntityName.ToLower());
            }

            EntityCollection result = new EntityCollection();

            OrganizationRequest  serviceRequest  = null;
            OrganizationResponse serviceResponse = null;

            switch (searchType)
            {
            case SearchTypeCode.FullText:
                serviceRequest = new FullTextSearchKnowledgeArticleRequest()
                {
                    QueryExpression  = query,
                    RemoveDuplicates = removeDuplicates,
                    SearchText       = searchText,
                    StateCode        = stateCode,
                    UseInflection    = useInflection
                };

                serviceResponse = this.OrganizationService.Execute(serviceRequest);
                result          = ((FullTextSearchKnowledgeArticleResponse)serviceResponse).EntityCollection;
                break;
            }

            return(result);
        }
        /// <summary>
        /// Search for <c>Knowledge Base Articles</c>.
        /// <para>
        /// For more information look at
        /// <c>By Body</c> : https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.searchbybodykbarticlerequest(v=crm.7).aspx
        /// <c>By Keyword</c> : https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.searchbykeywordskbarticlerequest(v=crm.7).aspx
        /// <c>By Title</c> : https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.searchbytitlekbarticlerequest(v=crm.7).aspx
        /// </para>
        /// </summary>
        /// <param name="searchType"><see cref="SearchTypeCode"/></param>
        /// <param name="subjectId">Knowledge base article subject Id</param>
        /// <param name="searchText">Text contained in the body of the article</param>
        /// <param name="useInflection">Indicates whether to use inflectional stem matching when searching for knowledge base articles with a specified body text</param>
        /// <returns>
        /// <see cref="EntityCollection"/> for <c>Article</c> data
        /// </returns>
        public EntityCollection Search(SearchTypeCode searchType, Guid subjectId, string searchText, bool useInflection)
        {
            ExceptionThrow.IfGuidEmpty(subjectId, "subjectId");
            ExceptionThrow.IfNullOrEmpty(searchText, "searchText");

            QueryExpression query = new QueryExpression(this.EntityName)
            {
                ColumnSet = new ColumnSet(true)
            };

            return(Search(searchType, query, subjectId, searchText, useInflection));
        }
        /// <summary>
        /// Search for <c>Knowledge Base Articles</c>.
        /// <para>
        /// For more information look at
        /// <c>By Body</c> : https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.searchbybodykbarticlerequest(v=crm.7).aspx
        /// <c>By Keyword</c> : https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.searchbykeywordskbarticlerequest(v=crm.7).aspx
        /// <c>By Title</c> : https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.searchbytitlekbarticlerequest(v=crm.7).aspx
        /// </para>
        /// </summary>
        /// <param name="searchType"><see cref="SearchTypeCode"/></param>
        /// <param name="query">
        /// Query criteria to find knowledge base articles with specified keyword.
        /// This parameter supports <c>QueryExpression</c> and <c>FetchXml</c>.
        /// </param>
        /// <param name="subjectId">Knowledge base article subject Id</param>
        /// <param name="searchText">Text contained in the body of the article</param>
        /// <param name="useInflection">Indicates whether to use inflectional stem matching when searching for knowledge base articles with a specified body text</param>
        /// <returns>
        /// <see cref="EntityCollection"/> for <c>Article</c> data
        /// </returns>
        public EntityCollection Search(SearchTypeCode searchType, QueryBase query, Guid subjectId, string searchText, bool useInflection)
        {
            ExceptionThrow.IfNull(query, "query");
            ExceptionThrow.IfGuidEmpty(subjectId, "subjectId");
            ExceptionThrow.IfNullOrEmpty(searchText, "searchText");

            EntityCollection result = new EntityCollection();

            if (query is QueryExpression)
            {
                ExceptionThrow.IfNullOrEmpty(((QueryExpression)query).EntityName, "QueryExpression.EntityName");
            }

            OrganizationRequest  request;
            OrganizationResponse serviceResponse;

            switch (searchType)
            {
            case SearchTypeCode.ByBody:
                //INFO : SDK Url --> https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.searchbybodykbarticlerequest(v=crm.7).aspx

                request = new SearchByBodyKbArticleRequest()
                {
                    QueryExpression = query,
                    SearchText      = searchText,
                    SubjectId       = subjectId,
                    UseInflection   = useInflection
                };

                serviceResponse = this.OrganizationService.Execute(request);
                result          = ((SearchByBodyKbArticleResponse)serviceResponse).EntityCollection;

                break;

            case SearchTypeCode.ByKeyword:
                //INFO : SDK Url --> https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.searchbykeywordskbarticlerequest(v=crm.7).aspx

                request = new SearchByKeywordsKbArticleRequest()
                {
                    QueryExpression = query,
                    SearchText      = searchText,
                    SubjectId       = subjectId,
                    UseInflection   = useInflection
                };

                serviceResponse = this.OrganizationService.Execute(request);
                result          = ((SearchByKeywordsKbArticleResponse)serviceResponse).EntityCollection;

                break;

            case SearchTypeCode.ByTitle:
                //INFO : SDK Url --> https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.searchbytitlekbarticlerequest(v=crm.7).aspx

                request = new SearchByTitleKbArticleRequest()
                {
                    QueryExpression = query,
                    SearchText      = searchText,
                    SubjectId       = subjectId,
                    UseInflection   = useInflection
                };

                serviceResponse = this.OrganizationService.Execute(request);
                result          = ((SearchByTitleKbArticleResponse)serviceResponse).EntityCollection;

                break;
            }

            return(result);
        }