private static void SetKeywordFilter(string keywords, bool isBasic, ref string where) { if (string.IsNullOrWhiteSpace(keywords)) { return; } //OR base.Description like '{0}' string text = " (base.name like '{0}' OR base.SubjectWebpage like '{0}' OR base.id in ( select EntityBaseId from Organization_AlternatesNames where TextValue like '{0}') ) "; string orgDepts = "( base.Id in (SELECT o.Id FROM dbo.Entity e INNER JOIN dbo.[Entity.AgentRelationship] ear ON e.Id = ear.EntityId INNER JOIN dbo.Organization o ON e.EntityUid = o.RowId WHERE ear.RelationshipTypeId = {0} AND o.StatusId < 4) )"; bool isCustomSearch = false; //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 Organization c on b.EntityUid = c.RowId where (b.EntityTypeId = 2 AND ( a.TextValue like '{0}' OR a.[CodedNotation] 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 (ServiceHelper.IsValidGuid(keywords)) { text = " ( CTID = 'ce-{0}' ) "; isCustomSearch = true; } else if (keywords.ToLower() == "[hascredentialregistryid]") { text = " ( len(Isnull(CredentialRegistryId,'') ) = 36 ) "; isCustomSearch = true; } else if (keywords.ToLower() == "has subsidiary") { text = string.Format(orgDepts, 21); isCustomSearch = true; } else if (keywords.ToLower() == "has department") { text = string.Format(orgDepts, 20); isCustomSearch = true; } 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( " % ", "%" ); } //same for now, but will chg if (isBasic || isCustomSearch) { where = where + AND + string.Format(" ( " + text + " ) ", keywords); } else { where = where + AND + string.Format(" ( " + text + indexFilter + " ) ", keywords); } }
private static void SetKeywordFilter(string keywords, bool isBasic, ref string where) { if (string.IsNullOrWhiteSpace(keywords)) { return; } //trim trailing (org) if (keywords.IndexOf("('") > 0) { keywords = keywords.Substring(0, keywords.IndexOf("('")); } //OR base.Description like '{0}' string text = " (base.name like '{0}' OR base.SubjectWebpage like '{0}' OR base.Organization 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 (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 Assessment c on b.EntityUid = c.RowId where (b.EntityTypeId = 3 AND ( a.TextValue like '{0}' OR a.[CodedNotation] like '{0}' ) ))) "; //string subjectsEtc = " OR (base.Id in (SELECT c.id FROM [dbo].[Entity.Reference] a inner join Entity b on a.EntityId = b.Id inner join Assessment c on b.EntityUid = c.RowId where [CategoryId] in (34 ,35) and a.TextValue like '{0}' )) "; //string frameworkItems = " OR (RowId in (SELECT EntityUid FROM [dbo].[Entity.FrameworkItemSummary] a where CategoryId= 23 and entityTypeId = 3 AND a.title like '{0}' ) ) "; //string otherFrameworkItems = " OR (RowId 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); } //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 + subjectsEtc + frameworkItems + otherFrameworkItems + " ) ", keywords ); }