<

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

Published on
10,565 Points
4,565 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
Author:ihnet
Enjoy this complimentary article view.

Get unlimited access to our entire library of technical procedures, guides, and tutorials written by certified industry professionals.

Get 7 days free
Click here to view the full article

Using this article for work? Experts Exchange can benefit your whole team.

Learn More
COLLABORATE WITH CERTIFIED PROFESSIONALS
Experts Exchange is a tech solutions provider where users receive personalized tech help from vetted certified professionals. These industry professionals also write and publish relevant articles on our site.
Ask questions about what you read
If you have a question about something within an article, you can receive help directly from the article author. Experts Exchange article authors are available to answer questions and further the discussion.
Learn from the best.