public SearchResultModel GetProjectSearchResults(string term, string version = null) { var filters = new List <SearchFilters>(); var searchFilters = new SearchFilters(BooleanOperation.And); //MUST be live searchFilters.Filters.Add(new SearchFilter("projectLive", "1")); filters.Add(searchFilters); //need to clean up this string, it could be all sorts of things if (version != null) { var parsedVersion = version.GetFromUmbracoString(); if (parsedVersion != null) { var numericalVersion = parsedVersion.GetNumericalValue(); var versionFilters = new SearchFilters(BooleanOperation.Or); versionFilters.Filters.Add(new RangeSearchFilter("num_version", 0, numericalVersion)); versionFilters.Filters.Add(new RangeSearchFilter("num_compatVersions", 0, numericalVersion)); filters.Add(versionFilters); } } var searcher = new OurSearcher(term, nodeTypeAlias: "project", filters: filters); var searchResult = searcher.Search("projectSearcher"); return(searchResult); }
public SearchResultModel GetDocsSearchResults(string term) { var searcher = new OurSearcher(term, nodeTypeAlias: "documentation"); var searchResult = searcher.Search("documentationSearcher"); return(searchResult); }
public HttpResponseMessage Search(string query, string version = null) { var filters = new List <SearchFilters>(); var searchFilters = new SearchFilters(BooleanOperation.And); //MUST be live searchFilters.Filters.Add(new SearchFilter("projectLive", "1")); filters.Add(searchFilters); if (version.IsNullOrWhiteSpace() == false) { //need to clean up this string, it could be all sorts of things var parsedVersion = version.GetFromUmbracoString(); if (parsedVersion != null) { var numericalVersion = parsedVersion.GetNumericalValue(); var versionFilters = new SearchFilters(BooleanOperation.Or); versionFilters.Filters.Add(new RangeSearchFilter("num_version", 0, numericalVersion)); versionFilters.Filters.Add(new RangeSearchFilter("num_compatVersions", 0, numericalVersion)); filters.Add(versionFilters); } } var ourSearcher = new OurSearcher(query, "project", maxResults: 100, filters: filters); var result = ourSearcher.Search("projectSearcher"); var resp = Request.CreateResponse( HttpStatusCode.OK, (IEnumerable <SearchResult>)result.SearchResults, Configuration.Formatters.JsonFormatter); return(resp); }
public SearchResultModel GetGlobalSearchResults(string term) { var searcher = new OurSearcher(term, maxResults: 5); var searchResult = searcher.Search(); return(searchResult); }
public SearchResultModel GetProjectSearchResults(string term, string version = null) { var filters = new List <SearchFilters>(); var searchFilters = new SearchFilters(BooleanOperation.And); //MUST be live searchFilters.Filters.Add(new SearchFilter("projectLive", "1")); filters.Add(searchFilters); //need to clean up this string, it could be all sorts of things if (version != null) { var parsedVersion = version.GetFromUmbracoString(); if (parsedVersion != null) { var numericalVersion = parsedVersion.GetNumericalValue(); var versionFilters = new SearchFilters(BooleanOperation.Or); versionFilters.Filters.Add(new RangeSearchFilter("num_version", 0, numericalVersion)); filters.Add(versionFilters); } } // track search var ga = new GoogleAnalytics(Request.Headers.GetCookies("_ga")); ga.SendSearchQuery(term, "projects"); var searcher = new OurSearcher(term, nodeTypeAlias: "project", filters: filters); var searchResult = searcher.Search("projectSearcher"); return(searchResult); }
public SearchResultModel GetProjectSearchResults(string term) { var searcher = new OurSearcher(term, nodeTypeAlias: "project"); var searchResult = searcher.Search(); return(searchResult); }
/// <summary> /// Returns a list of packages based on a search /// </summary> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="category"></param> /// <param name="query"></param> /// <param name="version"></param> /// <param name="order"></param> /// <returns></returns> /// <remarks> /// This caches each query for 2 minutes (non-sliding) /// </remarks> public PagedPackages GetPackages( int pageIndex, int pageSize, string category = null, string query = null, string version = null, PackageSortOrder order = PackageSortOrder.Default) { var filters = new List <SearchFilters>(); var searchFilters = new SearchFilters(BooleanOperation.And); //MUST be live searchFilters.Filters.Add(new SearchFilter("projectLive", "1")); filters.Add(searchFilters); if (version.IsNullOrWhiteSpace() == false) { //need to clean up this string, it could be all sorts of things var parsedVersion = version.GetFromUmbracoString(); if (parsedVersion != null) { var numericalVersion = parsedVersion.GetNumericalValue(); var versionFilters = new SearchFilters(BooleanOperation.Or); versionFilters.Filters.Add(new RangeSearchFilter("num_version", 0, numericalVersion)); versionFilters.Filters.Add(new RangeSearchFilter("num_compatVersions", 0, numericalVersion)); filters.Add(versionFilters); } } query = string.IsNullOrWhiteSpace(query) ? string.Empty : query; var orderBy = string.Empty; switch (order) { case PackageSortOrder.Latest: orderBy = "createDate[Type=LONG]"; break; case PackageSortOrder.Popular: orderBy = "popularity[Type=INT]"; break; } //Return based on a query if (!string.IsNullOrWhiteSpace(category)) { var catFilters = new SearchFilters(BooleanOperation.And); catFilters.Filters.Add(new SearchFilter("categoryFolder", string.Format("\"{0}\"", category))); filters.Add(catFilters); } var ourSearcher = new OurSearcher(query, nodeTypeAlias: "project", maxResults: pageSize * (pageIndex + 1), orderBy: orderBy, filters: filters); var searchResult = ourSearcher.Search("projectSearcher", skip: pageIndex * pageSize); return(FromSearchResults(searchResult, pageIndex, pageSize)); }
public SearchResultModel GetDocsSearchResults(string term, int version) { // track search var ga = new GoogleAnalytics(Request.Headers.GetCookies("_ga")); ga.SendSearchQuery(term, "docs"); var searcher = new OurSearcher(term, nodeTypeAlias: "documentation", majorDocsVersion: version); var searchResult = searcher.Search("documentationSearcher"); return(searchResult); }
public SearchResultModel GetGlobalSearchResults(string term) { // track search var ga = new GoogleAnalytics(Request.Headers.GetCookies("_ga")); ga.SendSearchQuery(term, "global"); var searcher = new OurSearcher(term, maxResults: 5); var searchResult = searcher.Search(); return(searchResult); }
public ActionResult Render(string q, string cat = "", string order = "", int fid = 0, bool solved = false, bool replies = false, int?v = null) { // If no search string specified, use a blank one to prevent null exceptions. if (string.IsNullOrEmpty(q)) { q = string.Empty; } if (q.StartsWith("duplicate content") && q.Contains("SELECT")) { q = string.Empty; } // A particular SQL injection attack uses this query which takes very long to process, turning it into and easy DOS attack // /search?q=999999.9' /**/uNiOn/**/aLl /**/sElEcT 0x393133353134353632312e39,0x393133353134353632322e39,0x393133353134353632332e39,0x393133353134353632342e39,0x393133353134353632352e39,0x393133353134353632362e39,0x393133353134353632372e39,0x393133353134353632382e39,0x393133353134353632392e39,0x39313335313435363231302e39,0x39313335313435363231312e39,0x39313335313435363231322e39,0x39313335313435363231332e39,0x39313335313435363231342e39,0x39313335313435363231352e39 and '0'='0-- if (q.Contains("999999.9'") || q.Contains("0x393133353134353632392e39")) { q = string.Empty; } var umbracoPage = this.CurrentPage; var nodeTypeAlias = cat; var forumName = string.Empty; var filters = new List <SearchFilters>(); if (nodeTypeAlias == "project") { var searchFilters = new SearchFilters(BooleanOperation.And); searchFilters.Filters.Add(new SearchFilter("projectLive", "1")); filters.Add(searchFilters); } if (nodeTypeAlias == "forum" && fid > 0) { var searchFilters = new SearchFilters(BooleanOperation.And); searchFilters.Filters.Add(new SearchFilter("parentId", fid)); filters.Add(searchFilters); var forum = Umbraco.ContentQuery.TypedContent(fid); var parentForum = forum.Parent; forumName = forum.Name + " - " + parentForum.Name; } if (solved) { var searchFilters = new SearchFilters(BooleanOperation.Not); searchFilters.Filters.Add(new SearchFilter("solved", "0")); filters.Add(searchFilters); } if (replies) { var searchFilters = new SearchFilters(BooleanOperation.Not); searchFilters.Filters.Add(new SearchFilter("replies", "0")); filters.Add(searchFilters); } var ourSearcher = new OurSearcher(q, //TODO: Depending on what order by this is, we need to pass in a data // type here, for example, if its an INT or a Date! orderBy: order, maxResults: 100, nodeTypeAlias: nodeTypeAlias, majorDocsVersion: v, filters: filters); var results = ourSearcher.Search(); var model = new SearchResultContentModel(umbracoPage, results); if (string.IsNullOrWhiteSpace(forumName) == false) { model.Results.Category = forumName; } return(PartialView("~/Views/Partials/SearchResults.cshtml", model)); }
public ActionResult Render(string q, string cat = "", string order = "", int fid = 0, bool solved = false, bool replies = false) { // A particular SQL injection attack uses this query which takes very long to process, turning it into and easy DOS attack // /search?q=999999.9' /**/uNiOn/**/aLl /**/sElEcT 0x393133353134353632312e39,0x393133353134353632322e39,0x393133353134353632332e39,0x393133353134353632342e39,0x393133353134353632352e39,0x393133353134353632362e39,0x393133353134353632372e39,0x393133353134353632382e39,0x393133353134353632392e39,0x39313335313435363231302e39,0x39313335313435363231312e39,0x39313335313435363231322e39,0x39313335313435363231332e39,0x39313335313435363231342e39,0x39313335313435363231352e39 and '0'='0-- if (q.Contains("0x393133353134353632392e39")) { Response.Redirect("/search?q="); } var umbracoPage = UmbracoContext.PublishedContentRequest.PublishedContent; var nodeTypeAlias = cat; //TODO: If we are searching on projects, they need to be filtered to approved/live! var forumName = string.Empty; var filters = new List <SearchFilters>(); if (nodeTypeAlias == "forum" && fid > 0) { var searchFilters = new SearchFilters(BooleanOperation.And); searchFilters.Filters.Add(new SearchFilter("parentId", fid)); filters.Add(searchFilters); var umbracoHelper = new UmbracoHelper(UmbracoContext.Current); var forum = umbracoHelper.ContentQuery.TypedContent(fid); var parentForum = forum.Parent; forumName = forum.Name + " - " + parentForum.Name; } if (solved) { var searchFilters = new SearchFilters(BooleanOperation.Not); searchFilters.Filters.Add(new SearchFilter("solved", "0")); filters.Add(searchFilters); } if (replies) { var searchFilters = new SearchFilters(BooleanOperation.Not); searchFilters.Filters.Add(new SearchFilter("replies", "0")); filters.Add(searchFilters); } var ourSearcher = new OurSearcher(q, //TODO: Depending on what order by this is, we need to pass in a data // type here, for example, if its an INT or a Date! orderBy: order, maxResults: 100, nodeTypeAlias: nodeTypeAlias, filters: filters); var results = ourSearcher.Search(); var model = new SearchResultContentModel(umbracoPage, results); if (string.IsNullOrWhiteSpace(forumName) == false) { model.Results.Category = forumName; } return(PartialView("~/Views/Partials/SearchResults.cshtml", model)); }