Example #1
0
        private void SimpleSearch()
        {
            var searchKeywords = headerSearch.Value;

            if (searchKeywords != keywords)
            {
                var url = NicamHelper.RedirectUrl(Consts.SearchResultPage, "search", searchKeywords);
                // Search Result Page
                Response.Redirect(url);
            }
        }
Example #2
0
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (NicamHelper.SafeRequest("search") != string.Empty)
                {
                    var searchWords = NicamHelper.UrlDecode(NicamHelper.SafeRequest("search"));

                    IEnumerable <Sitecore.Ecommerce.Search.SearchResult> resultHits = new LuceneSearcher(this.BuildQuery(searchWords), "web").Search();

                    List <Sitecore.Ecommerce.Search.SearchResult> results = new List <Sitecore.Ecommerce.Search.SearchResult>();
                    foreach (Sitecore.Ecommerce.Search.SearchResult resultHit in resultHits)
                    {
                        if (resultHit == null || resultHit.ResultItem == null || resultHit.ResultItem.ItemUri == null)
                        {
                            continue;
                        }

                        if (!results.Any(r => r.ResultItem.ItemLink == resultHit.ResultItem.ItemLink) && ItemUri.Parse(resultHit.ResultItem.ItemUri).Language == Sitecore.Context.Language && ItemUri.Parse(resultHit.ParentItem.ItemUri).Language == Sitecore.Context.Language)
                        {
                            results.Add(resultHit);
                        }
                    }

                    foreach (Sitecore.Ecommerce.Search.SearchResult resultHit in results)
                    {
                        TreeNode pnode = this.linksTree.Nodes.Cast <TreeNode>().FirstOrDefault(t => t.NavigateUrl == resultHit.ParentItem.ItemLink);

                        TreeNode node = new TreeNode(resultHit.ResultItem.ItemTitle)
                        {
                            NavigateUrl = resultHit.ResultItem.ItemLink,
                            Value       = resultHit.ResultItem.ItemUri
                        };

                        if (pnode == null)
                        {
                            pnode = new TreeNode(resultHit.ParentItem.ItemTitle)
                            {
                                NavigateUrl = resultHit.ParentItem.ItemLink,
                                Value       = resultHit.ParentItem.ItemUri
                            };
                            pnode.ChildNodes.Add(node);
                            this.linksTree.Nodes.Add(pnode);
                        }
                        else
                        {
                            pnode.ChildNodes.Add(node);
                        }
                    }

                    this.bodySearch.Value = searchWords;
                    AnalyticsUtil.Search(searchWords, resultHits.Count());
                }
            }
            else
            {
                if (SearchAgainClicked() && this.bodySearch.Value != string.Empty)
                {
                    var url = NicamHelper.RedirectUrl(Consts.SearchResultPage, "search", this.bodySearch.Value);
                    //// Search Result Page via QS only. It is necessary for Print version of page
                    Response.Redirect(url);
                }
            }
        }