<

how to limit the scope of an advanced search in Microsoft Search Server

Published on
10,466 Points
4,466 Views
Last Modified:
Approved
I have encountered the following problem while installing and configuring a Microsoft Search Server (actually it was a MSSO Express 2008, but I think it is applicable to other versions as well). Since I did not find an answer and I found an original one, I'm writing an article about it.

The problem
Suppose that you install your MSSE in order to index the content of all the servers in your company, and then you want to serve each department with the relevant dcoument searchs. It is straightforward to define several content sources, a search scope for every source, and a search site for each of the departments of your company, configured to search only the scopes that are relevant to that department. You may define scopes so that if a user uses the simple search has a nice dropdown list with only the scopes that are relevant for his department, and if she accesses the search site for department A search site, its "advanced search" scope picker lists only the scopes that are relevant to department A. You shoudl configure security that only users in department A can access http://yourserver/sites/searchA, and only users in department B can access http://yourserver/sites/searchB.  Good. Then try to perform an advanced search selecting NONE of the scopes. you can expect an error message saying tha tyou should select at least a scope, or you should expect a search in all the scopes for department A, but Microsoft extends the search over ALL the scopes that are configured on the sharepoint server, not to those that are configured on site A, also to those that are relevant for department B, and C, and so on!

The solution
The solution is to embed a little javascript into your advanced.aspx page. this javascript will intercept the submit action, check if there is at least one checkbox ticked and, if none is found, it ticks the first N checkboxes it finds. You should configure a variable in the code with the number of the checkboxes, i.e.: of the scopes in your scope picker

<script language=javascript>
// magic by RPIOLA (roberto@ilpiola.it) 20100210
// since microsoft search server's advanced search,
// if you do have a scope selector and you do not select
// any of the scopes, performs a global search,
// this javascript, inserted into a hidden webpart 
// on advanced.aspx, intercepts the form submit action,
// verifies if there is at least one checkbox ticked and,
// if none is found, ticks the first one, or the first N
// it finds. please configure into the global declaration
// global_ntocheck the number of the scopes you want to use
// as a default


global_ntockeck=8;



function my_onsubmit()
{
  var myresult='here comes the magic';
  var i;
  var thefirstone=-1;
  var onechecked=false;
  for(i=0; i<theForm.elements.length; i++)
  {
    if(theForm.elements[i].type=="checkbox")
    {
      if(thefirstone==-1)
        thefirstone=i;
      myresult=myresult+"; " + theForm.elements[i].name;
      if(theForm.elements[i].checked)
        onechecked=true;
    }
  }
  if(!onechecked)
  {
    if(thefirstone==-1)
      alert('you should tick at least one scope... but I didn\'t find any');
    else
    {
//      alert('you should tick at least one scope... I assumed the first one');
      theForm.elements[thefirstone].checked=true;
      ntocheck=global_ntockeck-1;
      for(i=thefirstone+1; i<theForm.elements.length && ntocheck>0; i++)
      {
        if(theForm.elements[i].type=="checkbox")
        {
           theForm.elements[i].checked=true;
           ntocheck--;
        }
      }
    }
  }
  return default_onsubmit();
}

default_onsubmit=WebForm_OnSubmit;
WebForm_OnSubmit=my_onsubmit;

</script>

Open in new window


The .js can be embedded in an invisible content web part without title. The sample code is configured for 8 scopes. you should use the source editor to adapt to your scopes. I prepared a .dwp package, but this site does not allow me to upload it :-(

Happy searches!

Roberto Piola
(roberto@ilpiola.it)
0
Comment
Author:ihnet
0 Comments

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Join & Write a Comment

Wrapper-1-Query. Use an Excel function to calculate a column for an Access query. Part 1. Shows a query in Access that has a calculated column with the results of an Excel worksheet function. See how to call a wrapper function from a query, and …
Discover the basics of using Outlook 2016 from office 365.

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month