error when paging advanced search results

Sep 5, 2008 at 1:26 AM
Has any one else had a problem with paging advanced search results? I get redirected to the error page when paging. I have not been able to trace this error but when I remove the faceted search wp the problem dissapears.
Sep 5, 2008 at 4:25 AM
On closer inspection it appears to be down to how the Utility class methods ExtractQuery and ExtractFormData - this code does not actually throw an exception but I think the logic here might be the source of the issue.

When you go from advanced search page to results page it is fine since the post data contains all the advanced search fields and the code executes as intended. As soon as you page however you get problems. The check for "POST" is going to be true for postbacks as well (like when you click the paging links) and the ExtractFormData will not find any of the advanced search data since they were part of the previous request. 

isAdvancedSearch will be false and the query method will get set to keyword query - but there will be no query string variables since we did an advanced search. I have come across this problem before, however for the web part I was writing it was enough just to pass what was required in the query string when the paging buttons were clicked. I don't really have any ideas how to do this for faceted search :( On the the paging post core results must get the query from viewstate or somewhere? You would need to persist the advanced search data or query between the paging postbacks somewhere I guess. Anyway I hope this is of some help.  


if

(HttpContext.Current.Request.HttpMethod == "POST")

 

{

 

FormData formData = ExtractFormData(out isAdvancedSearch);

 

query.FormData = formData;

query.IsAdvancedSearch = isAdvancedSearch;

query.QueryMethod =

QueryMethodEnum.FullTextSqlQuery;

 

}

 

if (!isAdvancedSearch)

 

{

query.QueryMethod =

QueryMethodEnum.KeywordQuery;

 

Sep 9, 2008 at 5:04 AM
The problem is to do with the Viewstate.
I disabled ViewState for the SearchFacets web part which stopped the exception but it has not fixed the problem .. paging advanced search results.
I think it would be good to persist the advanced search data which would allow for the paging of advanced search and also possibly returning to the original advanced search if you add then remove a facet. I.e. If you search for some keywords and a date range etc and then add a facet and then remove it  you will lose the date range portion of the original advanced search. 

The inner exception details... (this does not get logged anywhere so have to catch it before sharepoint does)
TARGETSITE: Boolean HandleError(System.Exception)MESSAGE: Failed to load viewstate.  The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.  For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.
STACKTRACE:    at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)
   at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
   at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)
   at System.Web.UI.Control.LoadChildViewStateByID(ArrayList childState)
   at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)
   at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
   at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)
   at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
   at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)
   at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
   at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)
   at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)
   at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)
   at System.Web.UI.Page.LoadAllState()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
SOURCE: System.Web
Developer
Sep 9, 2008 at 10:38 AM

Hi Caevyn,

Thank you for the feedback, there needs to be a period of of testing to reproduce and confirm the error.  If you have any further thoughts/results, please post them here.

Thanks again,

Shaun O'Callaghan

Sep 9, 2008 at 6:32 PM
I am having a similar issue.   I first noticed it and made a post a while ago regarding Javascript errors when running with Advanced Search.   It was throwing Javascript errors when the CallBack was made back to the server with the XML SearchQuery string.  I traced it with the Visual Studio debugger, and noticed that the FormData element does not look like it is being parsed or populated the second time around, which is where the AdvancedSearch Form data resides.   Therefore, it is making a empty Query, and throwing an error.   It does not throw an error if there are not enough results to cause the CallBack to the server to process the query the second time. 
Sep 10, 2008 at 4:13 AM
Edited Sep 10, 2008 at 4:30 AM
Well can't persist the query or formdata in viewstate since the code that  is executed in CreateChildControls() accesses the Query property on the base class resulting in the call to Utility.ExtractQuery(). I think this has to happen later in the page lifecycle to be able to store it in viewstate so that when the paging postback is triggered you could just get the info from viewstate instead of calling Utility.ExtractQuery which wont find any advanced search post data or a query string.   

I tried moving the CreateChildControls code to OnLoad, however this is pretty hacky refactoring:P It allows the use of view state to persist the SearchQuery (after making serializable) object which seems to solve the advanced search paging issue. Certainly unsure that such a change would not cause other problems however. Definately interested in more elegant solutions to solving this issue. 
Coordinator
Sep 12, 2008 at 2:37 PM
Edited Sep 12, 2008 at 2:38 PM
I'm looking into persisting SearchQuery in ViewState, updating the SearchQueryWebPart class. Here is the snippet
        internal SearchQuery Query
        {
            get
            {
                if (_query.IsEmpty())
                {
                    _query = Utility.ExtractQuery();
                }
                ViewState["SearchQuery"] = _query.GetXml().OuterXml;
                return _query.Clone();               
            }
        }


The query initializer must remain in CreateChildControls() to accomodate other scenarios. However, test (Query.Start > 0) might be sufficient to allow paging processing by de-serializing ViewState. This is yet to be confirmed.
Sep 21, 2008 at 1:30 AM
I did almost the exact thing for adding to ViewState, however still trying to find the best place to deserialise
Nov 24, 2008 at 8:26 AM
Edited Nov 24, 2008 at 8:26 AM
Hi,

I am having a similar issue.  When ever i click on paging i am getting javascript error.
I first noticed, It was throwing Javascript errors when the CallBack was made back to the server.

Any update on this, please help me how to resolve this javascript error.


Thanks
Meera
Dec 2, 2008 at 9:34 AM
Hi,

is there a solution for this problem by now?
Coordinator
Dec 2, 2008 at 1:41 PM
Edited Dec 2, 2008 at 1:44 PM
 same here
Coordinator
Dec 7, 2008 at 1:44 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.