private static void SetKeywordFilter(string keywords, bool isBasic, ref string where) { if (string.IsNullOrWhiteSpace(keywords) || string.IsNullOrWhiteSpace(keywords.Trim())) { return; } //trim trailing (org) if (keywords.IndexOf("('") > 0) { keywords = keywords.Substring(0, keywords.IndexOf("('")); } //OR base.Description like '{0}' var text = " (base.name like '{0}' OR base.Organization like '{0}' OR base.Description like '{0}' ) "; bool isCustomSearch = false; //for ctid, needs a valid ctid or guid if (keywords.IndexOf("ce-") > -1 && keywords.Length == 39) { text = " ( CTID = '{0}' ) "; isCustomSearch = true; } else if (ServiceHelper.IsValidGuid(keywords)) { text = " ( CTID = 'ce-{0}' ) "; isCustomSearch = true; } else if (ServiceHelper.IsInteger(keywords)) { text = " ( Id = '{0}' ) "; isCustomSearch = true; } else if (keywords.ToLower().IndexOf("orgid:") == 0) { string[] parts = keywords.Split(':'); if (parts.Count() > 1) { if (ServiceHelper.IsInteger(parts[1])) { text = string.Format(" ( OwningOrganizationId={0} ) ", parts[1].Trim()); isCustomSearch = true; } } } string AND = ""; if (where.Length > 0) { AND = " AND "; } keywords = ServiceHelper.HandleApostrophes(keywords); if (keywords.IndexOf("%") == -1 && !isCustomSearch) { keywords = SearchServices.SearchifyWord(keywords); } //skip url OR base.Url like '{0}' if (isBasic || isCustomSearch) { //if ( !includingFrameworkItemsInKeywordSearch ) // where = where + AND + string.Format( " ( " + text + " ) ", keywords ); //else where = where + AND + string.Format(" ( " + text + " ) ", keywords); } else { //if ( using_EntityIndexSearch ) // where = where + AND + string.Format( " ( " + text + indexFilter + " ) ", keywords ); //else where = where + AND + string.Format(" ( " + text + " ) ", keywords); } }
private static void SetKeywordFilter(string keywords, bool isBasic, ref string where) { if (string.IsNullOrWhiteSpace(keywords) || string.IsNullOrWhiteSpace(keywords.Trim())) { return; } //trim trailing (org) if (keywords.LastIndexOf("(") > 0) { keywords = keywords.Substring(0, keywords.LastIndexOf("(")); } //OR CreatorOrgs like '{0}' bool isCustomSearch = false; //OR base.Description like '{0}' OR base.SubjectWebpage like '{0}' string text = " (base.name like '{0}' OR base.AlternateName like '{0}' OR OwningOrganization like '{0}' ) "; //for ctid, needs a valid ctid or guid if (keywords.IndexOf("ce-") > -1 && keywords.Length == 39) { text = " ( CTID = '{0}' ) "; isCustomSearch = true; } else if (keywords.IndexOf("in (") > -1) { text = " base.Id " + keywords; isCustomSearch = true; } else if (ServiceHelper.IsValidGuid(keywords)) { text = " ( CTID = 'ce-{0}' ) "; isCustomSearch = true; } else if (ServiceHelper.IsInteger(keywords)) { text = " ( Id = '{0}' ) "; isCustomSearch = true; } else if (keywords.ToLower() == "[hascredentialregistryid]") { text = " ( len(Isnull(CredentialRegistryId,'') ) = 36 ) "; isCustomSearch = true; } //use Entity.SearchIndex for all string indexFilter = " OR (base.Id in (SELECT c.id FROM [dbo].[Entity.SearchIndex] a inner join Entity b on a.EntityId = b.Id inner join Credential c on b.EntityUid = c.RowId where (b.EntityTypeId = 1 AND ( a.TextValue like '{0}' OR a.[CodedNotation] like '{0}' ) ))) "; //removed 10,11 as part of the frameworkItemSummary //string keywordsFilter = " OR (base.Id in (SELECT c.id FROM [dbo].[Entity.Reference] a inner join Entity b on a.EntityId = b.Id inner join Credential c on b.EntityUid = c.RowId where [CategoryId] = 35 and a.TextValue like '{0}' )) "; // string subjects = " OR (base.EntityUid in (SELECT EntityUid FROM [Entity_Subjects] a where EntityTypeId = 1 AND a.Subject like '{0}' )) "; //string frameworkItems = " OR (EntityUid in (SELECT EntityUid FROM [dbo].[Entity.FrameworkItemSummary_ForCredentials] a where a.title like '{0}' ) ) "; // string otherFrameworkItems = " OR (EntityUid in (SELECT EntityUid FROM [dbo].[Entity_Reference_Summary] a where a.TextValue like '{0}' ) ) "; string AND = ""; if (where.Length > 0) { AND = " AND "; } // keywords = ServiceHelper.HandleApostrophes(keywords); if (keywords.IndexOf("%") == -1 && !isCustomSearch) { keywords = SearchServices.SearchifyWord(keywords); //keywords = "%" + keywords.Trim() + "%"; //keywords = keywords.Replace( "&", "%" ).Replace( " and ", "%" ).Replace( " in ", "%" ).Replace( " of ", "%" ); //keywords = keywords.Replace( " - ", "%" ); //keywords = keywords.Replace( " % ", "%" ); } //skip url OR base.Url like '{0}' if (isBasic || isCustomSearch) { where = where + AND + string.Format(" ( " + text + " ) ", keywords); } else { where = where + AND + string.Format(" ( " + text + indexFilter + " ) ", keywords); } //where = where + AND + string.Format( " ( " + text + keywordsFilter + subjects + frameworkItems + otherFrameworkItems + " ) ", keywords ); }