Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Abdul Raheem 17 posts 61 karma points
    Oct 15, 2014 @ 10:32
    Abdul Raheem
    0

    Paging in search is not working and search on inner pages only search the single page

    I am implementing search on Umbraco site using examine and user control. On Home page search works fine, but in inner page it only searches that single page. second issue is of paging it is not sending post back request to the server. I checked the console in google chrome it display "undefined fuction _dopostback()" Please help me in resolving the two issues, I am pasting my user control code here.

     

    SearchResults.ascx.cs

     

    namespace Adding_Value.usercontrols
     {
    public static class SiteSearchResultExtensions
    {
        public static string FullURL(this Examine.SearchResult sr)
        {
            return umbraco.library.NiceUrl(sr.Id);
        }
    }
    
    
    
    public partial class SiteSearchResults : System.Web.UI.UserControl
    {
        #region Properties
    
        private int _pageSize = 100;
        public string PageSize
        {
            get { return _pageSize.ToString(); }
            set
            {
                int pageSize;
                if (int.TryParse(value, out pageSize))
                {
                    _pageSize = pageSize;
                }
                else
                {
                    _pageSize = 100;
                }
            }
        }
    
        private string SearchTerm
        {
            get
            {
                object o = this.ViewState["SearchTerm"];
                if (o == null)
                    return "";
                else
                    return o.ToString();
            }
    
            set
            {
                this.ViewState["SearchTerm"] = value;
            }
        }
    
        protected IEnumerable<Examine.SearchResult> SearchResults
        {
            get;
            private set;
        }
    
        #endregion
    
        #region Events
    
        protected override void OnLoad(EventArgs e)
        {
            try
            {
                CustomValidator.ErrorMessage = "";
    
                if (!Page.IsPostBack)
                {
                    topDataPager.PageSize = _pageSize;
                    bottomDataPager.PageSize = _pageSize;
    
                    string terms = Request.QueryString["s"];
                    if (!string.IsNullOrEmpty(terms))
                    {
                        SearchTerm = terms;
                        PerformSearch(terms);
                    }
                }
    
                base.OnLoad(e);
            }
            catch (Exception ex)
            {
                CustomValidator.IsValid = false;
                CustomValidator.ErrorMessage += Environment.NewLine + ex.Message;
            }
        }
    
        protected void searchResultsListView_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
        {
            try
            {
                if (SearchTerm != "")
                {
                    topDataPager.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
                    bottomDataPager.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
                    PerformSearch(SearchTerm);
                }
            }
            catch (Exception ex)
            {
                CustomValidator.IsValid = false;
                CustomValidator.ErrorMessage += Environment.NewLine + ex.Message;
            }
        }
    
        #endregion
    
        #region Methods
    
        private void PerformSearch(string searchTerm)
        {
            if (string.IsNullOrEmpty(searchTerm)) return;
            //Node.GetCurrent();
            //Node Root = new Node(1050);
            //string rootNodeId = Root.Path.Split(',')[1];
            var criteria = ExamineManager.Instance
                .SearchProviderCollection["ExternalSearcher"]
                .CreateSearchCriteria(UmbracoExamine.IndexTypes.Content);
    
            //// Find pages that contain our search text in either their nodeName or bodyText fields...
            //// but exclude any pages that have been hidden.
            //var filter = criteria
            //    .GroupedOr(new string[] { "nodeName", "bodyText", "browserTitle", "tags", "mediaTags" }, searchTerm)
            //    .Not()
            //    .Field("umbracoNaviHide", "1")
            //    .Compile();
    
            //filter.And
    
            //SearchResults = ExamineManager.Instance
            //    .SearchProviderCollection["ExternalSearcher"]
            //    .Search(filter);
    
            Examine.SearchCriteria.IBooleanOperation filter = null;
            var searchKeywords = searchTerm.Split(' ');
            int i = 0;
            for (i = 0; i < searchKeywords.Length; i++)
            {
                if (filter == null)
                {
                    filter = criteria.GroupedOr(new string[] { "nodeName", "bodyText", "browserTitle", "tags", "mediaTags" }, searchKeywords[i]);
                }
                else
                {
                    filter = filter.Or().GroupedOr(new string[] { "nodeName", "bodyText", "browserTitle", "tags", "mediaTags" }, searchKeywords[i]);
                }
            }
    
            //only show results in the current path
            //var root = umbraco.NodeFactory.Node.GetNodeByXpath(+ umbraco.NodeFactory.Node.GetCurrent().Id + "]/ancestor-or-self::doctypealiasoftheroot");
            //GetNodeByXpath("$currentPage/ancestor-or-self::node [@level=1]");
    
            //filter.And().Field("SearchPath",rootNodeId);
            SearchResults = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"].Search(filter.Compile());
    
            if (SearchResults.Count() > 0)
            {
              // List<SearchResults>searchresuls = new List<SearchResults>();
              var  searchresuls = SearchResults.ToArray();
                for (int x = 0; x < SearchResults.ToArray().Length; x++)
                {
                    if (searchresuls[x].Fields["bodyText"].Length > 300)
                    {
                       searchresuls[x].Fields["bodyText"]=  searchresuls[x].Fields["bodyText"].Substring(0, 300)+"...";
                    }
                }
    
    
                searchResultsListView.DataSource = searchresuls;// SearchResults.ToArray();
    
               searchResultsListView.DataBind();
    
                searchResultsListView.Visible = true;
                bottomDataPager.Visible = topDataPager.Visible = (SearchResults.Count() > _pageSize);
            }
    
            summaryLiteral.Text = "<p>Your search for <b>" + searchTerm + "</b> returned <b>" + SearchResults.Count().ToString() + "</b> result(s)</p>";
    
            // Output the query which an be useful for debugging.
            queryLiteral.Text = criteria.ToString();
        }
    
        #endregion
    }
    }
    SearchResults.ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SiteSearchResults.ascx.cs" Inherits="Adding_Value.usercontrols.SiteSearchResults" %>
    
      <%@ Import Namespace="Adding_Value.usercontrols" %>
    
     <div class="col-md-12" id="SiteSearchResults">            
    <asp:ValidationSummary ID="ValidationSummary" runat="server" DisplayMode="List"  CssClass="validation" ValidationGroup="SiteSearchResults" />
    <asp:CustomValidator ID="CustomValidator" runat="server" Visible="False" ValidationGroup="SiteSearchResults"></asp:CustomValidator>
    
    <asp:Literal ID="summaryLiteral" runat="server" />
    
    <div style="display:none;">
        <asp:Literal ID="queryLiteral" runat="server" />
    </div>
    
    <div id="TopPagingControls">
        <asp:DataPager ID="topDataPager" PagedControlID="searchResultsListView" PageSize="5" Visible="false" runat="server">
        <Fields>
            <asp:NextPreviousPagerField ShowNextPageButton="False" RenderDisabledButtonsAsLabels="true" Visible="false" />
            <asp:NumericPagerField ButtonCount="10" CurrentPageLabelCssClass="currentpage" Visible="false" />
            <asp:NextPreviousPagerField  ShowPreviousPageButton="False" RenderDisabledButtonsAsLabels="true" Visible="false" />
        </Fields>
        </asp:DataPager>
    </div>
    
    <div class="col-md-12" id="SearchResults">            
        <asp:ListView ID="searchResultsListView"  runat="server" ItemPlaceholderID="itemPlaceholder" OnPagePropertiesChanging="searchResultsListView_PagePropertiesChanging">
            <LayoutTemplate>
                <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>       
            </LayoutTemplate>        
            <ItemTemplate>
                <li style="line-height: 15px;  list-style: none;">
    
                    <a class="search-heading custom " href="<%# ((Examine.SearchResult)Container.DataItem).FullURL() %>">
                        <%# ((Examine.SearchResult)Container.DataItem).Fields["nodeName"] %>
    
    
                        <p class="search-link">
                        addingvalue.webdevstaging.co.uk<%# ((Examine.SearchResult)Container.DataItem).FullURL() %>
                            </p> 
                    </a>
    
                    <p class="search-content"><%# ((Examine.SearchResult)Container.DataItem).Fields.ContainsKey("bodyText") == true ? 
                                              ((Examine.SearchResult)Container.DataItem).Fields["bodyText"] : ""%></p>
                </li>
            </ItemTemplate>
            <ItemSeparatorTemplate></ItemSeparatorTemplate>
            <EmptyDataTemplate></EmptyDataTemplate>
        </asp:ListView>
    </div>
    
    <div id="BottomPagingControls">
        <asp:DataPager ID="bottomDataPager" PagedControlID="searchResultsListView" PageSize="5" Visible="False" runat="server">
        <Fields>
            <asp:NextPreviousPagerField ShowNextPageButton="False" RenderDisabledButtonsAsLabels="true" Visible="true" />
            <asp:NumericPagerField ButtonCount="5" CurrentPageLabelCssClass="currentpage" Visible="true"/>
            <asp:NextPreviousPagerField  ShowPreviousPageButton="false" RenderDisabledButtonsAsLabels="true" Visible="true" />
        </Fields>
        </asp:DataPager>
    </div>
    </div>
  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Oct 15, 2014 @ 12:42
    Ismail Mayat
    0

    What version of umbraco are you using?

    Regards

    Ismail

  • Abdul Raheem 17 posts 61 karma points
    Oct 15, 2014 @ 15:28
    Abdul Raheem
    0

    I am using version 7

  • Abdul Raheem 17 posts 61 karma points
    Oct 16, 2014 @ 16:10
    Abdul Raheem
    0

    I have solved one issue i.e. of search results in inner pages I used java script to force search results to get url zbc/search?s=query I pasting the code

    Here is my form

    <div class="topLinks align_right right">

                            <div class="searchBox align_right">

                                <a href="javascript:void(0);">Search</a>

                                <div style="display: none;" class="searchPopup">

                                  @*  <form action="Search" method="get">*@

                                        <input type="" name="s" id="searchText"  onKeydown="Javascript: if (event.keyCode==13) searchRESLT();" />

                                        <input type="button" onclick="searchRESLT();" />

                                    @*</form>*@

                                </div>

                            </div>

                            <div class="rss-button">

                                <a class="rss-btn" href="#"></a>

                            </div>


                        </div>   

    and simple java script code

     <script>

            function searchRESLT() {

                window.parent.location = "/search.aspx?s=" + document.getElementById("searchText").value;

               

            }

        </script>

    
    
    <script type="text/javascript">// <![CDATA[
    </span><span class="kwd" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; color: #00008b; background: transparent;">function</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;"> searchRESLT</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">()</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">{</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;"> window</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">.</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">parent</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">.</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">location </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">=</span><span class="str" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; color: #800000; background: transparent;">"/search.aspx?s="</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">+</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;"> document</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">.</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">getElementById</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">(</span><span class="str" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; color: #800000; background: transparent;">"searchText"</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">).</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">value</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">;</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background: transparent;">}</span><span class="tag" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; color: #800000; background: transparent;">
    // ]]></script>
    Can any body please help me with paging issue y I am getting unassigned function __dopostback() in console. Thank you
Please Sign in or register to post replies

Write your reply to:

Draft