smart search text box

paul carter asked on February 21, 2020 09:50

The site i am currently take over has a smart text box filter defined in the master page. On my search page i have two smart filters defined and a search dialog with just the filter button visible. I also have a smart results web part. The issue is that i can enter a search value in the smart search text box click the search button and it redirects to my search page displaying the results, no problem. I would then expect to be able to use any of the other smart filters on the search page to further refine my filtering based on the original results. The problem is that the filtered value on from the text box does not seem to be maintained once a choose one of the other filters. Is their any way to rectify this ? I hope this makes sense. if you require any further detail or screen shots please advise

Recent Answers


paul carter answered on February 21, 2020 14:41

Hi , Just an update. I have checked the code, and the search dialog (custom) is passing a redirect to the search page with the search text in the URL. This is being picked up as a query string in the search results web part. I need to somehow retain this result set for my other two filters on the search page to filter on. Could this possible be a post back issue?

0 votesVote for this answer Mark as a Correct answer

Anil Bandela answered on February 21, 2020 15:27

Can you explain little more I was missing something here screenshot will be helpful.

Search web part work like that only once you search for something it will navigate to search page to display the filtered data.

use this kind of query string for fetch the key value

{% CurrentDocument.GetValue("SearchButton") #%}

Then write transformation according to this type to display the data

<%

var searchText = QueryHelper.GetText("searchtext", ""); var items = Eval("Items"); var msg = (String.IsNullOrWhiteSpace(searchText)) ? String.Format("{0} Results found.", items) : String.Format("{0} Results found for '{1}'", items, searchText);

var analytics = new {searchTerm= searchText, result= items}; var analyticsJSON = Newtonsoft.Json.JsonConvert.SerializeObject(analytics); var analyticsDOM = String.Format("<span id='hfSearchJson' class='GA-JSON' style='display: none'>{0}", analyticsJSON);

var totalMsg = IfEmpty(Eval("Items"), "", String.Format("

{0}
{1}", msg, analyticsDOM)); Response.Write(totalMsg);

%>

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on February 21, 2020 15:45

The search box and "search" button don't do a postback, they simply do a redirect to the "search results" page with the necessary URL parameter values. My suggestion would be to remove the search box webpart and add a filter webpart and set it to a textbox. This will perform a postback and persist the values you've chosen in the other filters.

2 votesVote for this answer Mark as a Correct answer

paul carter answered on February 21, 2020 15:51

Hi Anil,

Please see explanation. hope this helps

Hi Anil . The Search document is called using the following from the Master Page, which has the custom search dialog control ie

Extracts from master template Control <%@ Register TagPrefix="netc" TagName="SearchDialog" Src="~/SiteFiles/WebParts/SearchDialog.ascx" %>

This is a screen shot of the search dialog

Call to Search Page <netc:SearchDialog ID="desktopSearch" runat="server" SearchPageUrl="/search-results/" DefaultText="Search this site" />

This value is then picked up in the search results web part via the Search condition: MenuItemName:"{% QueryString["searchtext"] #%}" ProductCategoryName:"{% QueryString["searchtext"] #%}" NewsTitle:"{% QueryString["searchtext"] #%}" ProductName:"{% QueryString["searchtext"] #%}" Event

This is my search results page with two further smart search filters

So effectively the search condition picks up the text from the URL, but not, the value disappears from the search box upon loading the search page, even though it does retrieve the documents relating to the text. The problem seems that when I try to use the other two filters, which work fine together, I am loosing the original search condition which I want to also incorporate in the search, such as

User types frank in the text search User is directed to search page with filtered results showing User sets page types to Blog Search results display a subset of previous results generated by text search.

Hope this helps

Not too sure how to get screen shots to you ?

Best Regards,

Paul

0 votesVote for this answer Mark as a Correct answer

paul carter answered on February 21, 2020 15:56

Hi Brenden,

Trouble is the search box is currently integrated into our Master Template, and i am a bit weary of trying to change this at this stage in the game.I appreciate what you are saying about the URL, and understand. Just wondering if there was any other approach besides having to change the master page. Really not too sure why the original designers went for a custom search dialog.

0 votesVote for this answer Mark as a Correct answer

paul carter answered on February 21, 2020 15:59

Another potential thought i had, was to addhoc the master which has the search box . using the new adhoc for the new search page, and replacing the search box with the smart search dialog, while automatically accessing the value from the URL ? not too sure if this is a possibility, just trying to think of easy options ?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on February 21, 2020 16:05

This is a bit confusing, if the master page has a simple search dialog which redirects to a search page for the results, why even modify the master page? The master page search box's main functionality is to redirect to the search results page. The search results page should have it's own search textbox (filter) and other filters with a submit button. The submit button is simply a link button which causes a postback to refresh the filter, it's not the search dialog because that does a redirect to the search page and does not persist the filter values.

1 votesVote for this answer Mark as a Correct answer

paul carter answered on February 21, 2020 16:06

On Further reflection i assume the custom control was for the lovely layout of the search box with the search icon next to it :)

0 votesVote for this answer Mark as a Correct answer

paul carter answered on February 21, 2020 16:10

Well I have just inherited the site, and i understand what you are saying, but alas the custom search text box has been incorporated into the master page template, and is utilised by the search page, hence my dilemma.

0 votesVote for this answer Mark as a Correct answer

paul carter answered on February 21, 2020 16:19

So are you saying, as mentioned i can incorporate a new search dialog, out of the box on my search page and grab the value from the master, if it is initially entered at the home page level ?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on February 21, 2020 16:23

I'd render the master page search box in-operable on the search page. Thus making it do only what it is meant to do, function as a global search box which redirects to the search page. The search page has additional functionality on it to perform those searches/filters which do not include that master page textbox.

0 votesVote for this answer Mark as a Correct answer

paul carter answered on February 25, 2020 10:17

Hi Brenden, Thanks for the reply. So are you saying that i should include a separate search box on my search page ? but that would mean the user retyping the search text on the search page , would it not. I understand the logic. just want to make it user friendly ? Best regards

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on February 25, 2020 13:25

No it doesn't. You can set the value based on the query string value when the user is directed to the page for the first time.

0 votesVote for this answer Mark as a Correct answer

paul carter answered on February 25, 2020 14:27

So are you saying that i would Need to use a separate text search box on my search page which would utilise the value in the query string. Apologise for all the questions, just want to make sure i have understood. Regards, which in turn would give access to all the proper filter controls ?

0 votesVote for this answer Mark as a Correct answer

paul carter answered on February 25, 2020 15:49

Hi, Just an update. I added a search box on my search page, and used a query string to get the value. Seems to be working with the other filters on my page now, Thank you for the clarification Regards

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.