0

is there way to set Everything as default Search Scope to Search Box via jQuery. So when someone just enter text and hit search it will search in SearchCenter and not in osssearchresults.aspx.

And to remove This site completely.. I know that there is the way to do that via site settings > under site collection administration > search settings but there are a lot of Site Collections and sites and I don't want to do that manually for all of them.

ps. On picture is selected Conversations but I need Everything...

Search Dropdown

1 Answer 1

0

I solved this by replacing text in search text box and replacing keydown function search action... Here is code:

       //Function to Change default behavior of SearchBox
       function FixSearchBox() {
           var theSearchBox = $('#SearchBox input');
           var defaultSearchText = "Search this site";
           var preferredSearchText = "Search everything";
           var SearchCenterUrl = "/sites/search/"; 

           theSearchBox.val(preferredSearchText);
           theSearchBox.attr("title", preferredSearchText);
           theSearchBox.blur(function () {

               if ($(this).val().indexOf(defaultSearchText) > -1)
                   $(this).val(preferredSearchText);
           });
           theSearchBox.focus(function () {
               $(this).val("");
           });

           $("#SearchBox input").attr("onkeypress", "");
           $("#SearchBox input").keydown(function (e) {
               if (e.keyCode == "13") {
                   ProcessClick($("#SearchBox a[title='Search']"), preferredSearchText, SearchCenterUrl);
               }
           });
       }

       //Function for starting search
       function ProcessClick(button,preferredSearchText, SearchCenterUrl) {
           var query = $("#SearchBox input").val().replace(preferredSearchText,"*");
           var selectedSearch = $("div.ms-qSuggest-hListItem").text();

           if (query.length < 2 || query == '*') {
               document.location.href = SearchCenterUrl +"/Pages/results.aspx?k=*";
           }
           else {
               switch (selectedSearch) {
                   case "People":
                       document.location.href = SearchCenterUrl + "/Pages/peopleresults.aspx?k=" + query;
                       break;
                   case "Conversations":
                       document.location.href = SearchCenterUrl + "/Pages/conversationresults.aspx?k=" + query;
                       break;
                   case "Video":
                       document.location.href = SearchCenterUrl + "/Pages/videoresults.aspx?k=" + query;
                   default:
                       document.location.href = SearchCenterUrl + "/Pages/results.aspx?k=" + query;
                       break;
               }
           }
       }

PS. I added also a thing to search for '*' if you just click on search action (search icon).

to remove "Search this Site" from drop down I used css:

       div.ms-qSuggest-listItem:last-child
       {
         display:none;
       }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.