示例#1
0
        //TODO: Update this to accept a debug JObject
        public static MainSearchInput TranslateMainQueryToMainSearchInput(MainQuery query)
        {
            var translated = new MainSearchInput();

            translated.SearchType = query.SearchType;
            translated.Keywords   = query.Keywords;
            translated.StartPage  = query.SkipPages + 1;
            translated.PageSize   = query.PageSize;
            translated.SortOrder  = TranslateMainQuerySortOrderToMainSearchInputSortOrder(query.SortOrder);
            translated.FiltersV2  = TranslateMainQueryFiltersToMainSearchInputFilters(query.MainFilters, query.MapFilter);

            translated.WidgetId = query.WidgetFilter?.WidgetId ?? 0;
            //translated.MustHaveWidget = ? //TBD
            //translated.MustNotHaveWidget = ? //TBD

            translated.UseSimpleSearch = false;             //Probably always going to be false in this context?
            //translated.IncludingReferenceObjects = ? //TBD. Should probably be handled by a Filter instead.
            //translated.HasCredentialPotentialResults = ? //TBD
            //translated.CustomSearchInFields = ? //TBD

            //translated.CompetenciesKeywords = ? //TBD. Currently has 0 references in the MainSearch.cs file, so we may not need this.
            //translated.ElasticConfigs = ? //Only used with the development-only interface. No need to translate it.
            //translated.UseSPARQL = ? //Not used anymore. No need to translate it.
            //translated.Filters = ? //Not used anymore. No need to translate it.

            return(translated);
        }
示例#2
0
        public static List <ThisEntity> DoSearch(MainSearchInput data, ref int totalRows)
        {
            string where = "";
            List <string> competencies = new List <string>();

            //only target full entities
            where = " ( base.EntityStateId = 3 ) ";

            SearchServices.HandleCustomFilters(data, 61, ref where);

            SetKeywordFilter(data.Keywords, false, ref where);
            SearchServices.SetSubjectsFilter(data, CodesManager.ENTITY_TYPE_LEARNING_OPP_PROFILE, ref where);

            SetPropertiesFilter(data, ref where);
            SearchServices.SetRolesFilter(data, ref where);
            SearchServices.SetBoundariesFilter(data, ref where);
            //SetBoundariesFilter( data, ref where );

            //CIP
            SetFrameworksFilter(data, ref where);

            //Competencies
            SetCompetenciesFilter(data, ref where, ref competencies);

            LoggingHelper.DoTrace(5, "LearningOpportunityServices.Search(). Filter: " + where);
            return(EntityMgr.Search(where, data.SortOrder, data.StartPage, data.PageSize, ref totalRows, ref competencies));
        }
        /// <summary>
        /// Main search
        /// </summary>
        /// <param name="data"></param>
        /// <param name="pTotalRows"></param>
        /// <returns></returns>
        public static List <OrganizationSummary> DoSearch(MainSearchInput data, ref int pTotalRows)
        {
            string where = "";
            int userId = 0;

            AppUser user = AccountServices.GetCurrentUser();

            if (user != null && user.Id > 0)
            {
                userId = user.Id;
            }

            //only target full entities
            where = " ( base.EntityStateId = 3 ) ";

            SetKeywordFilter(data.Keywords, true, ref where);

            //SetAuthorizationFilter( user, ref where );
            SearchServices.HandleCustomFilters(data, 59, ref where);

            SetPropertiesFilter(data, ref where);
            SearchServices.SetRolesFilter(data, ref where);

            SetBoundariesFilter(data, ref where);
            SetFrameworksFilter(data, ref where);

            SetOrgServicesFilter(data, ref where);

            //check for org category (credentially, or QA). Only valid if one item
            //SetOrgCategoryFilter( data, ref where ); //Not updated - I'm not sure we're still using this. - NA 5/12/2017

            LoggingHelper.DoTrace(5, thisClassName + ".Search(). Filter: " + where);
            return(EntityMgr.MainSearch(where, data.SortOrder, data.StartPage, data.PageSize, ref pTotalRows));
        }
        public static List <ThisEntity> DoSearch(MainSearchInput data, ref int totalRows)
        {
            string where = "";
            List <string> competencies = new List <string>();
            int           userId       = 0;
            AppUser       user         = AccountServices.GetCurrentUser();

            if (user != null && user.Id > 0)
            {
                userId = user.Id;
            }

            //only target full entities
            where = " ( base.EntityStateId = 3 ) ";

            SetKeywordFilter(data.Keywords, false, ref where);

            SearchServices.SetSubjectsFilter(data, CodesManager.ENTITY_TYPE_ASSESSMENT_PROFILE, ref where);

            SearchServices.HandleCustomFilters(data, 60, ref where);

            SetPropertiesFilter(data, ref where);
            SearchServices.SetRolesFilter(data, ref where);
            SearchServices.SetBoundariesFilter(data, ref where);
            //CIP
            SetFrameworksFilter(data, ref where);
            //Competencies
            SetCompetenciesFilter(data, ref where, ref competencies);

            LoggingHelper.DoTrace(5, "AssessmentServices.Search(). Filter: " + where);
            return(EntityMgr.Search(where, data.SortOrder, data.StartPage, data.PageSize, ref totalRows));
        }
        /// <summary>
        /// Note these are now properties!!!
        /// Changed the view to use the properties view, and proper category
        /// </summary>
        /// <param name="data"></param>
        /// <param name="where"></param>
        private static void SetOrgServicesFilter(MainSearchInput data, ref string where)
        {
            string AND      = "";
            string template = " ( base.Id in ( SELECT  [OrganizationId] FROM [dbo].[Organization.ServiceSummary]  where [CodeId] in ({0}))) ";
            //don't really need categoryId - yet

            //Updated to use FiltersV2
            string next = "";

            if (where.Length > 0)
            {
                AND = " AND ";
            }
            foreach (var filter in data.FiltersV2.Where(m => m.Type == MainSearchFilterV2Types.CODE))
            {
                var item = filter.AsCodeItem();
                if (item.CategoryId == 6)
                {
                    next += item.Id + ",";
                }
            }
            next = next.Trim(',');
            if (!string.IsNullOrWhiteSpace(next))
            {
                where = where + AND + string.Format(template, next);
            }
        }
示例#6
0
        //

        //
        public JsonResult OrgSearch(MainSearchInput query)
        {
            query.IncludingReferenceObjects = true;
            MainSearchResults results = searchServices.MainSearch(query, ref valid, ref status);

            return(JsonHelper.GetJsonWithWrapper(results, valid, status, null));
        }
示例#7
0
        //
        public static List <ConceptSchemeSummary> Search(MainSearchInput data, ref int totalRows)
        {
            string where = "";
            List <string> messages     = new List <string>();
            List <string> competencies = new List <string>();

            //int userId = 0;
            //AppUser user = AccountServices.GetCurrentUser();
            //if ( user != null && user.Id > 0 )
            //	userId = user.Id;
            //only target records with a ctid
            where = " (len(Isnull(base.Ctid,'')) = 39) ";

            SetKeywordFilter(data.Keywords, false, ref where);
            //SearchServices.SetLanguageFilter( data, CodesManager.ENTITY_TYPE_CONCEPT_SCHEME, ref where );

            ////
            //SearchServices.SetAuthorizationFilter( user, "ConceptScheme_Summary", ref where );

            //SearchServices.HandleCustomFilters( data, 60, ref where );
            //

            //can this be replaced by following
            SearchServices.SetRolesFilter(data, ref where);

            //owned/offered
            //SearchServices.SetOrgRolesFilter( data, 3, ref where );
            //probably N/A
            SearchServices.SetBoundariesFilter(data, ref where);

            LoggingHelper.DoTrace(5, "ConceptSchemeServices.Search(). Filter: " + where);

            return(Manager.Search(where, data.SortOrder, data.StartPage, data.PageSize, ref totalRows));
        }
        public string MainSearch(MainSearchInput query)
        {
            //DateTime start = DateTime.Now;
            //LoggingHelper.DoTrace( 6, string.Format( "$$$$SearchController.MainSearch === Started: " ) );
            if (Request.Params["useSql"] == "true")
            {
                //query.useSql = true;
                //query.useElastic = false;
            }

            //if ( Request.Params["elastic"] == "true" ) query.ElasticSearch = true;


            var results = searchService.MainSearch(query, ref valid, ref status);

            //TimeSpan timeDifference = start.Subtract( DateTime.Now );
            //LoggingHelper.DoTrace( 6, string.Format( "$$$$SearchController.MainSearch === Ended - Elapsed: {0}", timeDifference.TotalSeconds ) );

            //Use a different return structure here because the default serialization method screws up the internal JObjects/JArrays/etc
            var finalResult = JObject.FromObject(new { data = results, valid = valid, status = status });

            Response.ContentType     = "application/json";
            Response.ContentEncoding = Encoding.UTF8;
            return(finalResult.ToString());
        }
示例#9
0
 public static List <CommonSearchSummary> Search(MainSearchInput data, ref int pTotalRows)
 {
     if (UtilityManager.GetAppKeyValue("usingElasticTransferValueSearch", false))
     {
         //var results = ElasticHelper.GeneralSearch( CodesManager.ENTITY_TYPE_TRANSFER_VALUE_PROFILE, data, ref pTotalRows );
         return(ElasticHelper.GeneralSearch(CodesManager.ENTITY_TYPE_TRANSFER_VALUE_PROFILE, "TransferValue", data, ref pTotalRows));
     }
     else
     {
         List <CommonSearchSummary> results = new List <CommonSearchSummary>();
         var list = DoSearch(data, ref pTotalRows);
         foreach (var item in list)
         {
             results.Add(new CommonSearchSummary()
             {
                 Id                      = item.Id,
                 Name                    = item.Name,
                 Description             = item.Description,
                 SubjectWebpage          = item.SubjectWebpage,
                 PrimaryOrganizationName = item.PrimaryOrganizationName,
                 CTID                    = item.CTID,
                 EntityTypeId            = CodesManager.ENTITY_TYPE_TRANSFER_VALUE_PROFILE,
                 EntityType              = "TransferValueProfile"
             });
         }
         return(results);
     }
 }        //
        }        //

        public static List <CommonSearchSummary> PathwaySetSearch2(MainSearchInput data, ref int pTotalRows)
        {
            if (UtilityManager.GetAppKeyValue("usingElasticPathwaySetSearch", false))
            {
                return(ElasticHelper.PathwaySetSearch(data, ref pTotalRows));
            }
            else
            {
                List <CommonSearchSummary> results = new List <CommonSearchSummary>();
                var list = DoPathwaySetSearch(data, ref pTotalRows);
                foreach (var item in list)
                {
                    results.Add(new CommonSearchSummary()
                    {
                        Id                      = item.Id,
                        Name                    = item.Name,
                        Description             = item.Description,
                        SubjectWebpage          = item.SubjectWebpage,
                        PrimaryOrganizationName = item.PrimaryOrganizationName,
                        CTID                    = item.CTID,
                        EntityTypeId            = CodesManager.ENTITY_TYPE_PATHWAY_SET,
                        EntityType              = "PathwaySet"
                    });
                }
                return(results);
            }
        }        //
 public static List <PathwaySetSummary> PathwaySetSearch(MainSearchInput data, ref int pTotalRows)
 {
     //if ( UtilityManager.GetAppKeyValue( "usingElasticPathwaySetSearch", false ) )
     //{
     //	return ElasticHelper.PathwaySetSearch( data, ref pTotalRows );
     //}
     //else
     {
         //var results = new List<CommonSearchSummary>();
         var list = DoPathwaySetSearch(data, ref pTotalRows);
         //foreach ( var item in list )
         //{
         //	results.Add( new CommonSearchSummary()
         //	{
         //		Id = item.Id,
         //		Name = item.Name,
         //		Description = item.Description,
         //		SubjectWebpage = item.SubjectWebpage,
         //		PrimaryOrganizationName = item.PrimaryOrganizationName,
         //		CTID = item.CTID,
         //		EntityTypeId = CodesManager.ENTITY_TYPE_PATHWAY_SET,
         //		EntityType = "PathwaySet"
         //	} );
         //}
         return(list);
     }
 }        //
示例#12
0
        //public static List<ThisEntity> Search( string keywords, int pageNumber, int pageSize, ref int totalRows )
        //{
        //	string pOrderBy = "";
        //	string filter = "";
        //	int userId = 0;
        //	AppUser user = AccountServices.GetCurrentUser();
        //	if ( user != null && user.Id > 0 )
        //		userId = user.Id;

        //	SetKeywordFilter( keywords, true, ref filter );
        //	//SetAuthorizationFilter( user, ref filter );

        //	return EntityMgr.Search( filter, pOrderBy, pageNumber, pageSize, ref totalRows );
        //}

        public static List <ThisEntity> Search(MainSearchInput data, ref int pTotalRows)
        {
            if (UtilityManager.GetAppKeyValue("usingElasticLearningOppSearch", false))
            {
                return(ElasticServices.LearningOppSearch(data, ref pTotalRows));
            }
            else
            {
                return(DoSearch(data, ref pTotalRows));
            }
        }
 public static List <OrganizationSummary> Search(MainSearchInput data, ref int pTotalRows)
 {
     if (UtilityManager.GetAppKeyValue("usingElasticOrganizationSearch", false))
     {
         return(ElasticHelper.OrganizationSearch(data, ref pTotalRows));
     }
     else
     {
         return(DoSearch(data, ref pTotalRows));
     }
 }
 /// <summary>
 /// Full credentials search
 /// </summary>
 /// <param name="data"></param>
 /// <param name="pTotalRows"></param>
 /// <returns></returns>
 public static List <ThisSearchEntity> Search(MainSearchInput data, ref int pTotalRows)
 {
     if (UtilityManager.GetAppKeyValue("usingElasticCredentialSearch", false) || data.Elastic)
     {
         return(ElasticHelper.Credential_Search(data, ref pTotalRows));
     }
     else
     {
         return(DoSearch(data, ref pTotalRows));
     }
 }
        //public static List<ThisEntity> Search( string keywords, int pageNumber, int pageSize, ref int totalRows )
        //{
        //	string pOrderBy = "";
        //	string filter = "";
        //	int userId = 0;
        //	AppUser user = AccountServices.GetCurrentUser();
        //	if ( user != null && user.Id > 0 )
        //		userId = user.Id;

        //	SetKeywordFilter( keywords, true, ref filter );
        //	//SetAuthorizationFilter( user, ref filter );

        //	return EntityMgr.Search( filter, pOrderBy, pageNumber, pageSize, ref totalRows );
        //}

        public static List <ThisEntity> Search(MainSearchInput data, ref int pTotalRows)
        {
            if (UtilityManager.GetAppKeyValue("usingElasticAssessmentSearch", false))
            {
                return(ElasticHelper.AssessmentSearch(data, ref pTotalRows));
            }
            else
            {
                return(DoSearch(data, ref pTotalRows));
            }
        }
示例#16
0
        private static void SetCompetenciesAutocompleteFilter(string keywords, ref string where)
        {
            List <string>    competencies = new List <string>();
            MainSearchInput  data         = new MainSearchInput();
            MainSearchFilter filter       = new MainSearchFilter()
            {
                Name = "competencies", CategoryId = 29
            };

            filter.Items.Add(keywords);
            SetCompetenciesFilter(data, ref where, ref competencies);
        }
示例#17
0
        private static void SetFrameworksFilter(MainSearchInput data, ref string where)
        {
            string AND           = "";
            string codeTemplate2 = "  (base.Id in (SELECT c.id FROM [dbo].[Entity.FrameworkItemSummary] a inner join Entity b on a.EntityId = b.Id inner join LearningOpportunity c on b.EntityUid = c.RowId where [CategoryId] = {0} and ([FrameworkGroup] in ({1})  OR ([CodeId] in ({2}) )  ))  ) ";

            string codeTemplate = " (base.Id in (SELECT c.id FROM [dbo].[Entity_ReferenceFramework_Summary] a inner join Entity b on a.EntityId = b.Id inner join LearningOpportunity c on b.EntityUid = c.RowId where [CategoryId] = {0} and ([CodeGroup] in ({1})  OR ([ReferenceFrameworkId] in ({2}) )  )) ) ";
            //Updated to use FiltersV2
            string next   = "";
            string groups = "";

            if (where.Length > 0)
            {
                AND = " AND ";
            }
            var targetCategoryID = 23;

            foreach (var filter in data.FiltersV2.Where(m => m.Type == MainSearchFilterV2Types.FRAMEWORK))
            {
                var item       = filter.AsCodeItem();
                var isTopLevel = filter.GetValueOrDefault <bool>("IsTopLevel", false);
                if (item.CategoryId == targetCategoryID)
                {
                    if (isTopLevel)
                    {
                        groups += item.Id + ",";
                    }
                    else
                    {
                        next += item.Id + ",";
                    }
                }
            }
            if (next.Length > 0)
            {
                next = next.Trim(',');
            }
            else
            {
                next = "''";
            }
            if (groups.Length > 0)
            {
                groups = groups.Trim(',');
            }
            else
            {
                groups = "''";
            }
            if (groups != "''" || next != "''")
            {
                where = where + AND + string.Format(codeTemplate, targetCategoryID, groups, next);
            }
        }
示例#18
0
        //

        //Search for organizations related to some entity type
        public JsonResult RelatedEntitySearch(SelectionQuery query)
        {
            /* Temporary */
            //TODO - Determine whether or not this needs to be replaced with a method that cares about the Relationship type (perhaps limit results to QA orgs?)
            var searchQuery = new MainSearchInput()
            {
                SearchType = query.SearchType.ToLower(), StartPage = query.PageNumber, PageSize = query.PageSize, Keywords = query.Keywords, UseSimpleSearch = query.UseSimpleSearch, SortOrder = query.SortOrder
            };


            searchQuery.IncludingReferenceObjects = true;
            MainSearchResults results = searchServices.MainSearch(searchQuery, ref valid, ref status);

            return(JsonHelper.GetJsonWithWrapper(results, valid, status, null));
            /* End Temporary */
        }
示例#19
0
        public void SearchOld()
        {
            MainSearchInput query = new MainSearchInput()
            {
                SearchType = "credential",
                StartPage  = 1,
                PageSize   = 25,
                SortOrder  = "newest"
            };

            var results = searchService.MainSearch(query, ref valid, ref status);

            var finalResult = JObject.FromObject(new { data = results, valid = valid, status = status });

            SendResponse(finalResult);
        }
        private static void SetBoundariesFilter(MainSearchInput data, ref string where)
        {
            string AND = "";

            if (where.Length > 0)
            {
                AND = " AND ";
            }
            string template = " ( base.Id in ( SELECT  [EntityBaseId] FROM [dbo].[Entity_AddressSummary] where EntityTypeId = 2 AND  [Longitude] < {0} and [Longitude] > {1} and [Latitude] < {2} and [Latitude] > {3} ) ) ";

            var boundaries = SearchServices.GetBoundaries(data, "bounds");

            if (boundaries.IsDefined)
            {
                where = where + AND + string.Format(template, boundaries.East, boundaries.West, boundaries.North, boundaries.South);
            }
        }
        //
        private static void SetPropertiesFilter(MainSearchInput data, ref string where)
        {
            string AND = "";
            string searchCategories = UtilityManager.GetAppKeyValue("asmtSearchCategories", "21,37,");

            SearchServices.SetPropertiesFilter(data, 1, searchCategories, ref where);
            //string template = " ( base.Id in ( SELECT  [EntityBaseId] FROM [dbo].[EntityProperty_Summary] where EntityTypeId= 3 AND {0} )) ";
            //string template1 = " ( base.Id in ( SELECT  [EntityBaseId] FROM [dbo].[EntityProperty_Summary] where EntityTypeId= 3 AND [PropertyValueId] in ({0}) )) ";
            //string properyListTemplate = " ( [PropertyValueId] in ({0}) ) ";
            //string filterList = "";
            //int prevCategoryId = 0;

            ////Updated to use FiltersV2
            //string next = "";
            //if (where.Length > 0)
            //    AND = " AND ";
            //foreach (var filter in data.FiltersV2.Where(m => m.Type == MainSearchFilterV2Types.CODE))
            //{
            //    var item = filter.AsCodeItem();
            //    if (searchCategories.Contains(item.CategoryId.ToString()))
            //    {
            //        //18-03-27 mp - these are all property values, so using an AND with multiple categories will always fail - removing prevCategoryId check
            //        //if (item.CategoryId != prevCategoryId)
            //        //{
            //        //    if (prevCategoryId > 0)
            //        //    {
            //        //        next = next.Trim(',');
            //        //        filterList += (filterList.Length > 0 ? " AND " : "") + string.Format(properyListTemplate, next);
            //        //    }
            //        //    prevCategoryId = item.CategoryId;
            //        //    next = "";
            //        //}
            //        next += item.Id + ",";
            //    }
            //}
            //next = next.Trim(',');
            //if (!string.IsNullOrWhiteSpace(next))
            //{
            //    //where = where + AND + string.Format( template, next );
            //    filterList += (filterList.Length > 0 ? " AND " : "") + string.Format(properyListTemplate, next);
            //    where = where + AND + string.Format(template, filterList);
            //}
        } //
示例#22
0
        //

        #region Old to New

        public static MainQuery TranslateMainSearchInputToMainQuery(MainSearchInput query)
        {
            var translated = new MainQuery();

            translated.SearchType = query.SearchType;

            translated.SearchType   = query.SearchType;
            translated.Keywords     = query.Keywords;
            translated.SkipPages    = query.StartPage - 1;
            translated.PageSize     = query.PageSize;
            translated.SortOrder    = TranslateMainSearchInputSortOrderToMainQuerySortOrder(query.SortOrder);
            translated.MainFilters  = TranslateMainSearchInputFiltersToMainQueryFilters(query.FiltersV2);
            translated.WidgetFilter = query.WidgetId > 0 ? new WidgetFilter()
            {
                WidgetId = query.WidgetId
            } : null;

            return(translated);
        }
        private static void SetCompetenciesFilter(MainSearchInput data, ref string where, ref List <string> competencies)
        {
            string AND     = "";
            string OR      = "";
            string keyword = "";
            //just learning opps
            //string template = " ( base.Id in (SELECT distinct  CredentialId FROM [dbo].[ConditionProfile_Competencies_Summary]  where AlignmentType in ('teaches', 'assesses') AND ({0}) ) ) ";
            //learning opps and asmts:
            string template = " ( base.Id in (SELECT distinct  CredentialId FROM [dbo].[ConditionProfile_Competencies_Summary]  where ({0}) ) ) ";
            //
            string phraseTemplate = " ([Name] like '%{0}%' OR [TargetNodeDescription] like '%{0}%') ";
            //

            //Updated to use FiltersV2
            string next = "";

            if (where.Length > 0)
            {
                AND = " AND ";
            }
            foreach (var filter in data.FiltersV2.Where(m => m.Name == "competencies"))
            {
                var text = filter.AsText();

                //No idea what this is supposed to do
                try
                {
                    if (text.IndexOf(" - ") > -1)
                    {
                        text = text.Substring(text.IndexOf(" -- ") + 4);
                    }
                }
                catch { }

                competencies.Add(text.Trim());
                next += OR + string.Format(phraseTemplate, text.Trim());
                OR    = " OR ";
            }
            if (!string.IsNullOrWhiteSpace(next))
            {
                where = where + AND + string.Format(template, next);
            }
        }
示例#24
0
        public void Search2(string searchType = "")
        {
            if (string.IsNullOrWhiteSpace(searchType))
            {
                searchType = "credential";
            }
            MainSearchInput query = new MainSearchInput()
            {
                SearchType = searchType,
                StartPage  = 1,
                PageSize   = 25,
                SortOrder  = "newest"
            };

            var results = searchService.MainSearch(query, ref valid, ref status);

            var finalResult = JObject.FromObject(new { data = results, valid = valid, status = status });

            SendResponse(finalResult);
        }
        }        //

        public static List <PathwaySetSummary> DoPathwaySetSearch(MainSearchInput data, ref int totalRows)
        {
            string where = "";

            //only target full entities
            where = " ( base.EntityStateId = 3 ) ";

            //need to create a new category id for custom filters
            //SearchServices.HandleCustomFilters( data, 61, ref where );

            SetKeywordFilter(data.Keywords, false, ref where);
            SearchServices.SetSubjectsFilter(data, CodesManager.ENTITY_TYPE_PATHWAY, ref where);

            //SetPropertiesFilter( data, ref where );
            SearchServices.SetRolesFilter(data, ref where);
            SearchServices.SetBoundariesFilter(data, ref where);


            LoggingHelper.DoTrace(5, "PathwayServices.DoPathwaySetSearch(). Filter: " + where);
            return(PathwaySetManager.Search(where, data.SortOrder, data.StartPage, data.PageSize, ref totalRows));
        }
示例#26
0
        public void MainSearchOld(MainSearchInput searchQuery)
        {
            var response = new ApiResponse();

            try
            {
                var results = searchService.MainSearch(searchQuery, ref valid, ref status);

                //var finalResult = JObject.FromObject( new { data = results, valid = valid, status = status } );
                response.Successful = true;
                response.Result     = results;
                SendResponse(response);
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, "CredentialFinderWebAPI.MainSearchOld. " + ex.Message);
                response.Messages.Add(string.Format("Error encountered returning data. {0} ", ex.Message));
                response.Successful = false;
                SendResponse(response);
            }
        }
示例#27
0
        private static void SetCompetenciesFilter(MainSearchInput data, ref string where, ref List <string> competencies)
        {
            string AND            = "";
            string OR             = "";
            string template       = " ( base.Id in (SELECT distinct LearningOpportunityId FROM [dbo].LearningOpportunity_Competency_Summary  where AlignmentType = 'teaches' AND ({0}) ) )";
            string phraseTemplate = " ([Name] like '%{0}%' OR [Description] like '%{0}%') ";
            //

            //Updated to use FiltersV2
            string next = "";

            if (where.Length > 0)
            {
                AND = " AND ";
            }
            foreach (var filter in data.FiltersV2.Where(m => m.Name == "competencies"))
            {
                var text = filter.AsText();

                //No idea what this is supposed to do
                try
                {
                    if (text.IndexOf(" - ") > -1)
                    {
                        text = text.Substring(text.IndexOf(" -- ") + 4);
                    }
                }
                catch { }

                competencies.Add(text.Trim());
                next += OR + string.Format(phraseTemplate, text.Trim());
                OR    = " OR ";
            }
            if (!string.IsNullOrWhiteSpace(next))
            {
                where = where + AND + string.Format(template, next);
            }
        }
示例#28
0
        }        //

        public static List <ThisEntity> DoSearch(MainSearchInput data, ref int totalRows)
        {
            string where = "";
            List <string> competencies = new List <string>();

            //only target full entities
            where = " ( base.EntityStateId = 3 ) ";
            //need to create a new category id for custom filters
            //SearchServices.HandleCustomFilters( data, 61, ref where );

            SetKeywordFilter(data.Keywords, false, ref where);
            //SearchServices.SetSubjectsFilter( data, CodesManager.ENTITY_TYPE_TRANSFER_VALUE_PROFILE, ref where );

            //SetPropertiesFilter( data, ref where );
            SearchServices.SetRolesFilter(data, ref where);
            SearchServices.SetBoundariesFilter(data, ref where);

            //Competencies
            //SetCompetenciesFilter( data, ref where, ref competencies );

            LoggingHelper.DoTrace(5, "TransferValueServices.Search(). Filter: " + where);
            return(EntityMgr.Search(where, data.SortOrder, data.StartPage, data.PageSize, ref totalRows));
        }
        private static void SetOrgCategoryFilter(MainSearchInput data, ref string where)
        {
            string AND = "";
            //check for org category (credentially, or QA). Only valid if one item
            var qaSettings = data.GetFilterValues_Strings("qualityAssurance");

            if (qaSettings.Count == 1)
            {
                //ignore unless one filter
                string item = qaSettings[0];
                if (where.Length > 0)
                {
                    AND = " AND ";
                }
                if (item == "includeNormal")                   //IsAQAOrganization = false
                {
                    where = where + AND + " ([IsAQAOrganization] = 0 OR [CredentialCount] > 0) ";
                }
                else if (item == "includeQualityAssurance")                    //IsAQAOrganization = true
                {
                    where = where + AND + " ([IsAQAOrganization] = 1) ";
                }
            }
        }
        public static ComposedSearchResultSet SearchViaRegistry(MainSearchInput sourceQuery, bool asDescriptionSet = false, int descriptionSetPerBranchLimit = 10)
        {
            //Hold the query
            var apiQuery = new SearchQuery();

            //Hold the response
            var results = new ComposedSearchResultSet();

            //Handle blind searches
            sourceQuery.Keywords = (sourceQuery.Keywords ?? "").Trim();
            if (string.IsNullOrWhiteSpace(sourceQuery.Keywords))
            {
                apiQuery.SkipLogging = true;                 //No need to log the blind searches that auto-happen when a user visits the search page
                apiQuery.Query       = new JObject()
                {
                    { "@type", "ceasn:CompetencyFramework" }
                };
            }
            //Otherwise, look for the value in various places
            else
            {
                //Normalize the text
                var normalized      = Regex.Replace(Regex.Replace(sourceQuery.Keywords.ToLower().Trim(), "[^a-z0-9-\" ]", " "), " +", " ");
                var ctids           = Regex.Matches(normalized, @"\b(ce-[a-f0-9-]{0,36})\b").Cast <Match>().Select(m => m.Value).ToList();
                var wordsAndPhrases = normalized.Split(' ').Where(m => !ctids.Contains(m.Replace("\"", ""))).ToList();
                var keywords        = string.Join(" ", wordsAndPhrases);

                //Basic skeleton
                apiQuery.Query = new JObject()
                {
                    { "@type", "ceasn:CompetencyFramework" },
                    { "search:termGroup", new JObject()
                      {
                          { "search:operator", "search:orTerms" },
                          { "ceasn:creator", new JObject() },
                          { "ceasn:publisher", new JObject() },
                          { "ceasn:isPartOf", new JObject() }
                      } }
                };

                //Add CTID-based query data
                if (ctids.Count() > 0)
                {
                    var ctidList = JArray.FromObject(ctids);
                    apiQuery.Query["search:termGroup"]["ceterms:ctid"] = ctidList;
                    apiQuery.Query["search:termGroup"]["ceasn:isPartOf"]["ceterms:ctid"]  = ctidList;
                    apiQuery.Query["search:termGroup"]["ceasn:creator"]["ceterms:ctid"]   = ctidList;
                    apiQuery.Query["search:termGroup"]["ceasn:publisher"]["ceterms:ctid"] = ctidList;
                }

                //Add non-CTID-based query data
                if (keywords.Count() > 0)
                {
                    //Framework
                    apiQuery.Query["search:termGroup"]["ceasn:name"]        = keywords;
                    apiQuery.Query["search:termGroup"]["ceasn:description"] = keywords;
                    apiQuery.Query["search:termGroup"]["ceasn:source"]      = keywords;
                    //Creator
                    apiQuery.Query["search:termGroup"]["ceasn:creator"]["ceterms:name"]           = keywords;
                    apiQuery.Query["search:termGroup"]["ceasn:creator"]["ceterms:subjectWebpage"] = keywords;
                    apiQuery.Query["search:termGroup"]["ceasn:creator"]["search:operator"]        = "search:orTerms";
                    //Publisher
                    apiQuery.Query["search:termGroup"]["ceasn:publisher"]["ceterms:name"]           = keywords;
                    apiQuery.Query["search:termGroup"]["ceasn:publisher"]["ceterms:subjectWebpage"] = keywords;
                    apiQuery.Query["search:termGroup"]["ceasn:publisher"]["search:operator"]        = "search:orTerms";
                    //Competencies
                    apiQuery.Query["search:termGroup"]["ceasn:isPartOf"]["ceasn:competencyLabel"] = keywords;
                    apiQuery.Query["search:termGroup"]["ceasn:isPartOf"]["ceasn:competencyText"]  = keywords;
                    apiQuery.Query["search:termGroup"]["ceasn:isPartOf"]["ceasn:comment"]         = keywords;
                    apiQuery.Query["search:termGroup"]["ceasn:isPartOf"]["search:operator"]       = "search:orTerms";
                }
            }

            //Handle paging
            apiQuery.Skip = sourceQuery.PageSize * (sourceQuery.StartPage - 1);
            apiQuery.Take = sourceQuery.PageSize;

            //Include metadata so that we can display when the record was created/updated in the registry
            apiQuery.IncludeResultsMetadata = true;

            //Include debug info for now
            apiQuery.IncludeDebugInfo = true;

            //Handle sort order
            apiQuery.Sort =
                sourceQuery.SortOrder == "alpha" ? "ceasn:name" :
                sourceQuery.SortOrder == "newest" ? "search:recordUpdated" :                 //Use ceasn:dateModified instead if we want to see newest according to that rather than the Registry record date
                sourceQuery.SortOrder == "relevance" ? (string)null :
                null;

            //Handle description set
            if (asDescriptionSet)
            {
                apiQuery.DescriptionSetType             = SearchQuery.DescriptionSetTypes.Resource_RelatedURIs_RelatedData;
                apiQuery.DescriptionSetRelatedURIsLimit = descriptionSetPerBranchLimit;                 //Use -1 for no limit
            }
            else
            {
                apiQuery.DescriptionSetType = SearchQuery.DescriptionSetTypes.Resource;
            }

            //Help with logging
            apiQuery.ExtraLoggingInfo = new JObject();
            apiQuery.ExtraLoggingInfo.Add("Source", "Finder/Search/CompetencyFramework");
            apiQuery.ExtraLoggingInfo.Add("ClientIP", HttpContext.Current?.Request?.UserHostAddress ?? "unknown");
            results.DebugInfo.Add("Raw Query", JObject.FromObject(apiQuery));

            //Do the query
            var rawResults = DoRegistrySearchAPIQuery(apiQuery);

            results.DebugInfo.Add("Raw Results", JObject.FromObject(rawResults));
            if (!rawResults.valid)
            {
                results.DebugInfo.Add("Error Performing Search", rawResults.status);
                return(results);
            }

            //Compose the results
            try
            {
                results.TotalResults = rawResults.extra.TotalResults;
                results.RelatedItems = rawResults.extra.RelatedItems;
                results.DebugInfo.Add("Query Debug", rawResults.extra.DebugInfo);
                foreach (var result in rawResults.data)
                {
                    var composed = new ComposedSearchResult();
                    composed.Data = result;

                    var uri = result["@id"].ToString();
                    composed.RelatedItemsMap = rawResults.extra.RelatedItemsMap?.Where(m => m.ResourceURI == uri).SelectMany(m => m.RelatedItems).OrderBy(m => m.Path).ToList();
                    composed.Metadata        = rawResults.extra.ResultsMetadata?.FirstOrDefault(m => m["ResourceURI"] != null && m["ResourceURI"].ToString() == uri);

                    results.Results.Add(composed);
                }
            }
            catch (Exception ex)
            {
                results.DebugInfo.Add("Error Composing Results", ex.Message);
                return(results);
            }

            //Return the results
            return(results);
        }