开发者

People search in SharePoint using partial names

My employer is switching their internal portal over to SharePoint. One of the highly used features of the previous portal 开发者_开发知识库was a 'people search' that allowed partial names. SharePoint 2007 defaults to keyword searches which only match against the exact word(s) given as search terms. It can do full-text searches but you have to provide the property name, e.g. "FirstName:tom" (without the quotes of course). That works for a programmatic solution but not for end users.

Is there a way in SharePoint 2007 to let users search for people using partial names?


I found this solution that works well enough for us.

Add a ContentEditor web part to the target page and go to the HTML editor button. Add the following HTML code. It creates two input fields (firstname/lastname) and then creates a query with the search terms included as property searches which will invoke the full-text search.

Note: you need to replace the search result page with the appropriate location for your configuration.

<script language="javascript">
//function to handle enter on keyboard
function txtWildPeopleFinder_KeyDown(e)
{
  if (e.keyCode == 13 || e.keyCode==10)
  {
    e.returnValue=false;
    DoWildPeopleSearch();
    return false;
  }
  else
    return true;
}
//escape apostrophes in search strings
function escapestr(str)
{
 return str.replace("'","%22");
}

//search function
function DoWildPeopleSearch()
{
var firstname = escapestr(document.all["firstname"].value);
var lastname =  escapestr(document.all["lastname"].value);
var url;

//search on last name
if(firstname == "")
{
 url = "/searchcenter/Pages/peopleresults.aspx?k=LastName%3A" + lastname;
 window.location=url;
 return;
}

//search on first name
if(lastname == "")
{
 url = "/searchcenter/Pages/peopleresults.aspx?k=FirstName%3A" + firstname;
 window.location=url;
 return;
}

//first and last
 url = "/searchcenter/Pages/peopleresults.aspx?k=lastname%3A" + lastname +  "%20FirstName%3A" + firstname;
 window.location=url;
 return;
}
</script>

<table cellpadding="2" cellspacing="0" border="0" width="100%" ID="Table3">
 <tr>
  <td width="80" nowrap>
   First Name:
  </td>
  <td width="100%">
   <input size="20" maxlength="100" id="firstname" name="firstname" type="text" onkeydown="txtWildPeopleFinder_KeyDown(event)">
  </td>
 </tr>
 <tr>
  <td width="80" nowrap>
   Last Name:
  </td>
  <td>
   <input size="20" maxlength="100" id="lastname" name="lastname" type="text" onkeydown="txtWildPeopleFinder_KeyDown(event)">
  </td>
 </tr>
 <tr>
  <td> &nbsp; </td>
  <td>
   <input type="button" onclick="DoWildPeopleSearch()" value="Search">
  </td>
 </tr>

</table>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜