|
Rank: Advanced Member
Groups: Registered
Joined: 2/29/2008 Posts: 43
|
I have a page with a SearchBox and SearchResult, plus some options that let the user set the scope of the search. When they click search, I handle SearchBox.Search and use the settings to set the categories for the SearchBox.SearchOptions. This works well.
Once the results are displayed, I want to update them automatically when the user changes a setting. So for example they uncheck a category, I want to rerun the search with the new categories. How do I do this? If I handle the postback and update the categories for the SearchBox, that doesn't refilter the results that are shown in the SearchResult.
|
|
Rank: Advanced Member
Groups: Registered
Joined: 2/29/2008 Posts: 43
|
I tried doing this by doing the search myself using a SearchAgent:
Dim agent = SearchResult1.SearchAgent agent.LicenseKey = System.Configuration.ConfigurationManager.AppSettings("Keyoti-SearchEngine-LicenseKey")
Dim options As New Keyoti.SearchEngine.Search.SearchOptions() Dim results = agent.Search(searchText.Text, options, 1, SearchResult1.NumberOfResultsPerPage) SearchResult1.SearchResults = results SearchResult1.QueryExpression = searchText.Text
When this loads I get an InvalidOperationException: "Cannot access NumberOfResults property until after the NumberOfResultsFinalized event - now is too early in the control lifecycle"
|
|
Rank: Advanced Member
Groups: Administrators, Registered
Joined: 8/13/2004 Posts: 2,669 Location: Canada
|
Bill, you don't need the code in the 2nd post. To explain, initially before the SearchResult control has performed a search, you correctly set the SearchOptions in the SearchBox (because that is sending the options). Once the SearchResult control is showing results, you need to change the SearchOptions in the SearchResult control Code: private void Bt1_Click(object sender, EventArgs e) { SearchResult1.SearchOptions = new SearchOptions("news", null); }
It worked for me. -your feedback is helpful to other users, thank you!
|
|
Rank: Advanced Member
Groups: Registered
Joined: 2/29/2008 Posts: 43
|
I will try that out. Can you explain why the other approach isn't working, though? I realized that the NumberOfResults property was getting retrieved from the display template for the SearchResults. I took that out and no longer got an exception, but the control didn't display any results (even though I confirmed that results are being retrieved). Is the SearchResult control not intended to be used independent of the SearchBox?
|
|
Rank: Advanced Member
Groups: Administrators, Registered
Joined: 8/13/2004 Posts: 2,669 Location: Canada
|
You can use the SearchResult control without the SearchBox, I think it didn't do what you expected (assuming the 'results' object has data in it) perhaps because of the ASP.NET page lifecycle - you may have to call InvalidateChildHeirarchy. -your feedback is helpful to other users, thank you!
|
|
Rank: Advanced Member
Groups: Registered
Joined: 2/29/2008 Posts: 43
|
When I replaced the SearchResult.SearchOptions, the page showed no results. I used the same code to build the SearchOptions that I used initially to set it for the SearchBox.
When I instead replaced the ContentCategoryNames of the existing SearchResult.SearchOptions, it gave me the desired result.
|
|