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 GetForumSearchResults(string term, string forum = "")
        {
            int forumId;
            var filters = new List<SearchFilters>();
            if (int.TryParse(forum, out forumId))
            {
                var searchFilters = new SearchFilters(BooleanOperation.And);
                searchFilters.Filters.Add(new SearchFilter("parentId", forumId.ToString()));
                filters.Add(searchFilters);
            }

            var searcher = new OurSearcher(term, nodeTypeAlias: "forum", filters: filters);
            var searchResult = searcher.Search();

            foreach (var result in searchResult.SearchResults)
            {
                result.Fields["url"] = result.FullUrl();

                //Since these results are going to be displayed in the forum, we need to convert the date field to 
                // the 'relative' value that is normally shown for the forum date
                var updateDate = result.Fields["updateDate"] = DateTools.StringToDate(result.Fields["updateDate"]).ConvertToRelativeTime();
            }

            

            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 GetDocsSearchResults(string term)
 {
     var searcher = new OurSearcher(term, nodeTypeAlias: "documentation");
     var searchResult = searcher.Search();
     return searchResult;
 }
 public SearchResultModel GetProjectSearchResults(string term)
 {
     var searcher = new OurSearcher(term, nodeTypeAlias:"project");
     var searchResult = searcher.Search();
     return searchResult;
 }
 public SearchResultModel GetGlobalSearchResults(string term)
 {
     var searcher = new OurSearcher(term, maxResults: 5);
     var searchResult = searcher.Search();
     return searchResult;
 }
Exemple #7
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!IsPostBack)
            {
                var umbracoPage = UmbracoContext.PublishedContentRequest.PublishedContent;

                var nodeTypeAlias = Request.QueryString["cat"];

                int forumId;
                var forumName = string.Empty;
                var filters = new List<SearchFilters>();
                if (nodeTypeAlias == "forum" && int.TryParse(Request.QueryString["fid"], out forumId))
                {
                    var searchFilters = new SearchFilters(BooleanOperation.And);
                    searchFilters.Filters.Add(new SearchFilter("parentId", forumId.ToString()));
                    filters.Add(searchFilters);

                    var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
                    var forum = umbracoHelper.ContentQuery.TypedContent(forumId);
                    var parentForum = forum.Parent;
                    forumName = forum.Name + " - " + parentForum.Name;
                }

                if (string.IsNullOrWhiteSpace(Request.QueryString["solved"]) == false)
                {
                    bool onlySolvedItems;
                    if (bool.TryParse(Request.QueryString["solved"], out onlySolvedItems) && onlySolvedItems)
                    {
                        var searchFilters = new SearchFilters(BooleanOperation.Not);
                        searchFilters.Filters.Add(new SearchFilter("solved", "0"));
                        filters.Add(searchFilters);
                    }
                }

                if (string.IsNullOrWhiteSpace(Request.QueryString["replies"]) == false)
                {
                    bool onlyIfReplies;
                    if (bool.TryParse(Request.QueryString["replies"], out onlyIfReplies) && onlyIfReplies)
                    {
                        var searchFilters = new SearchFilters(BooleanOperation.Not);
                        searchFilters.Filters.Add(new SearchFilter("replies", "0"));
                        filters.Add(searchFilters);
                    }
                }

                var orderBy = string.Empty;
                if (string.IsNullOrWhiteSpace(Request.QueryString["order"]) == false)
                {
                    orderBy = Request.QueryString["order"];
                }

                var ourSearcher = new OurSearcher(Request.QueryString["q"],
                    orderBy: orderBy,
                    maxResults: 100,
                    nodeTypeAlias:
                    nodeTypeAlias,
                    filters: filters);

                var results = ourSearcher.Search();

                Model = new SearchResultContentModel(umbracoPage, results);
                if (string.IsNullOrWhiteSpace(forumName) == false)
                    Model.Results.Category = forumName;

                SearchText.Text = Model.Results.SearchTerm;
            }
            else
            {
                Response.Redirect("/search?q=" + SearchText.Text);
            }

        }