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
namespaceAdding_Value.usercontrols
{publicstaticclassSiteSearchResultExtensions{publicstaticstringFullURL(thisExamine.SearchResult sr){return umbraco.library.NiceUrl(sr.Id);}}publicpartialclassSiteSearchResults:System.Web.UI.UserControl{#region Propertiesprivateint _pageSize =100;publicstringPageSize{get{return _pageSize.ToString();}set{int pageSize;if(int.TryParse(value,out pageSize)){
_pageSize = pageSize;}else{
_pageSize =100;}}}privatestringSearchTerm{get{object o =this.ViewState["SearchTerm"];if(o ==null)return"";elsereturn o.ToString();}set{this.ViewState["SearchTerm"]= value;}}protectedIEnumerable<Examine.SearchResult>SearchResults{get;privateset;}#endregion#region EventsprotectedoverridevoidOnLoad(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;}}protectedvoid 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 MethodsprivatevoidPerformSearch(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(newstring[]{"nodeName","bodyText","browserTitle","tags","mediaTags"}, searchKeywords[i]);}else{
filter = filter.Or().GroupedOr(newstring[]{"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}}
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();" />
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
SearchResults.ascx
What version of umbraco are you using?
Regards
Ismail
I am using version 7
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>
is working on a reply...