private List <SResult> SearchTermForWeb(string terms) { List <SResult> results = new List <SResult>(); if (!string.IsNullOrEmpty(terms)) { // var criteria = searcher.CreateSearchCriteria(); //IBooleanOperation query = criteria.Field("contents", searchQuery.MultipleCharacterWildcard()); // Find pages that contain our search text in either their nodeName or bodyText fields... // but exclude any pages that have been hidden. // searchCriteria.Fields("nodeName",terms.Boost(8)).Or().Field("metaTitle","hello".Boost(5)).Compile(); Examine.SearchCriteria.ISearchCriteria crawl = null; Examine.SearchCriteria.ISearchCriteria crawlRestricted = null; if (User.Identity.IsAuthenticated) { //this block of if is for the loggedin users... string[] roles = System.Web.Security.Roles.GetRolesForUser(User.Identity.Name); var criteriaRestricted = ExamineManager.Instance .SearchProviderCollection["WebsiteSearcher"] .CreateSearchCriteria(); //if there is space search for exact word. IExamineValue srcTerm; if (terms.Contains(" ")) { srcTerm = terms.ToLower().Escape(); } else { srcTerm = terms.ToLower().MultipleCharacterWildcard(); } crawlRestricted = criteriaRestricted.GroupedOr(new string[] { "bodyText", "nodeName", "name", "menuline1", "menuline2", "title", "featurecontent", "seo" }, srcTerm) .And().Field("GroupAccess", roles[0]) //.Or().Field("IsPublic", "true") //THE OR condition does not work as // when IsPublic = ture group access is null //so i have to combine both results.. .Not().Field("umbracoNaviHide", "1") .Not().Field("nodeTypeAlias", "Image") .Compile(); ISearchResults SearchResultsRestricted = ExamineManager.Instance .SearchProviderCollection["WebsiteSearcher"] .Search(crawlRestricted); foreach (var sr in SearchResultsRestricted) { SResult result = new SResult() { Id = sr.Fields.ContainsKey("id") ? sr.Fields["id"] : "", //Score = sr.Fields.ContainsKey("Score") ? (int)Math.Min(sr.Score * 100, 100) : 0, // Url = sr.Fields.ContainsKey("urlName") ? sr.Fields["urlName"] : "", //Url = sr.Fields.ContainsKey("Url") ? sr.Fields["Url"] : "", Url = Umbraco.Content(sr.Fields["id"]).Url, NodeName = sr.Fields.ContainsKey("nodeName") ? sr.Fields["nodeName"] : "", Text = sr.Fields.ContainsKey("bodyText") ? sr.Fields["bodyText"] : "", FText = sr.Fields.ContainsKey("featurecontent") ? sr.Fields["featurecontent"] : "", Date = sr.Fields.ContainsKey("updateDate") ? sr.Fields["updateDate"] : "", }; result.Text = result.Text.Substring(0, Math.Min(result.Text.Length, 250)); result.FText = result.FText.Substring(0, Math.Min(result.FText.Length, 250)); results.Add(result); } var criteria = ExamineManager.Instance .SearchProviderCollection["WebsiteSearcher"] .CreateSearchCriteria(); crawl = criteria.GroupedOr(new string[] { "bodyText", "nodeName", "name", "menuline1", "menuline2", "title", "featurecontent", "seo" }, terms.ToLower().MultipleCharacterWildcard()) .Not().Field("umbracoNaviHide", "1") .Not().Field("nodeTypeAlias", "Image") .And().Field("IsPublic", "true") .Compile(); ISearchResults SearchResults = ExamineManager.Instance .SearchProviderCollection["WebsiteSearcher"] .Search(crawl); foreach (var sr in SearchResults) { SResult result = new SResult() { Id = sr.Fields.ContainsKey("id") ? sr.Fields["id"] : "", Url = Umbraco.Content(sr.Fields["id"]).Url, NodeName = sr.Fields.ContainsKey("nodeName") ? sr.Fields["nodeName"] : "", Text = sr.Fields.ContainsKey("bodyText") ? sr.Fields["bodyText"] : "", FText = sr.Fields.ContainsKey("featurecontent") ? sr.Fields["featurecontent"] : "", Date = sr.Fields.ContainsKey("updateDate") ? sr.Fields["updateDate"] : "", }; result.Text = result.Text.Substring(0, Math.Min(result.Text.Length, 250)); result.FText = result.FText.Substring(0, Math.Min(result.FText.Length, 250)); results.Add(result); } } else { //this block for not authenticated... var criteria = ExamineManager.Instance .SearchProviderCollection["WebsiteSearcher"] .CreateSearchCriteria(); //if there is space search for exact word. IExamineValue srcTerm; if (terms.Contains(" ")) { srcTerm = terms.ToLower().Escape(); } else { srcTerm = terms.ToLower().MultipleCharacterWildcard(); } crawl = criteria.GroupedOr(new string[] { "bodyText", "nodeName", "name", "menuline1", "menuline2", "title", "featurecontent", "seo" }, srcTerm) .Not().Field("umbracoNaviHide", "1") .Not().Field("nodeTypeAlias", "Image") .And().Field("IsPublic", "true") .Compile(); ISearchResults SearchResults = ExamineManager.Instance .SearchProviderCollection["WebsiteSearcher"] .Search(crawl); foreach (var sr in SearchResults) { SResult result = new SResult() { Id = sr.Fields.ContainsKey("id") ? sr.Fields["id"] : "", //Score = sr.Fields.ContainsKey("Score") ? (int)Math.Min(sr.Score * 100, 100) : 0, // Url = sr.Fields.ContainsKey("urlName") ? sr.Fields["urlName"] : "", //Url = sr.Fields.ContainsKey("Url") ? sr.Fields["Url"] : "", Url = Umbraco.Content(sr.Fields["id"]).Url, NodeName = sr.Fields.ContainsKey("nodeName") ? sr.Fields["nodeName"] : "", Text = sr.Fields.ContainsKey("bodyText") ? sr.Fields["bodyText"] : "", FText = sr.Fields.ContainsKey("featurecontent") ? sr.Fields["featurecontent"] : "", Date = sr.Fields.ContainsKey("updateDate") ? sr.Fields["updateDate"] : "", }; result.Text = result.Text.Substring(0, Math.Min(result.Text.Length, 250)); result.FText = result.FText.Substring(0, Math.Min(result.FText.Length, 250)); results.Add(result); } } } //sort it: // if (results.Count>0) // results = results.OrderBy(o => o.NodeName).ToList(); //sort it by LastLoginDate this is the default.. if (results.Count > 0) { results = results.OrderByDescending(o => o.Date).ToList(); } return(results); }
private List <SResult> SearchTermForEvents(string terms) { //the resource will be searched only for the logged in users List <SResult> results = new List <SResult>(); if (!string.IsNullOrEmpty(terms)) { Examine.SearchCriteria.ISearchCriteria crawlResourceRestricted = null; if (User.Identity.IsAuthenticated) { string[] roles = System.Web.Security.Roles.GetRolesForUser(User.Identity.Name); //Resouce search var criteriaResourceRestricted = ExamineManager.Instance .SearchProviderCollection["EventSearcher"] .CreateSearchCriteria(); //if there is space search for exact word. IExamineValue srcTerm; if (terms.Contains(" ")) { srcTerm = terms.ToLower().Escape(); } else { srcTerm = terms.ToLower().MultipleCharacterWildcard(); } crawlResourceRestricted = criteriaResourceRestricted.GroupedOr(new string[] { "description", "eventtitle", "nodeName", "name", "seo", "intendedaudiences" }, srcTerm) .And().Field("roles", roles[0]) .Compile(); ISearchResults SearchResultsResourceRestricted = ExamineManager.Instance .SearchProviderCollection["EventSearcher"] .Search(crawlResourceRestricted); foreach (var sr in SearchResultsResourceRestricted) { SResult result = new SResult() { Id = sr.Fields.ContainsKey("id") ? sr.Fields["id"] : "", Url = Umbraco.Content(sr.Fields["id"]).Url, NodeName = sr.Fields.ContainsKey("nodeName") ? sr.Fields["nodeName"] : "", Text = sr.Fields.ContainsKey("description") ? sr.Fields["description"] : "", Date = sr.Fields.ContainsKey("updateDate") ? sr.Fields["updateDate"] : "", }; result.Text = result.Text.Substring(0, Math.Min(result.Text.Length, 250)); result.FText = ""; if (result.Text.Length > 249 && !result.Text.EndsWith(".")) { result.FText = "1"; } results.Add(result); } } } //sort it by LastLoginDate this is the default.. if (results.Count > 0) { results = results.OrderByDescending(o => o.Date).ToList(); } return(results); }
/// <summary> /// Searhes content /// </summary> /// <param name="criteria"></param> /// <param name="searchProvider"></param> /// <returns></returns> public IEnumerable <IPublishedContent> TypedSearch(Examine.SearchCriteria.ISearchCriteria criteria, Examine.Providers.BaseSearchProvider searchProvider = null) { var total = 0; return(TypedSearch(0, 0, out total, criteria, searchProvider)); }