2010-11-17 80 views
2

我的雇主将他们的内部门户切换到SharePoint。之前的门户网站高度使用的功能之一是允许部分名称的“人员搜索”。 SharePoint 2007默认使用的关键字搜索仅与搜索条件中给出的确切词相匹配。它可以进行全文搜索,但必须提供属性名称,例如“名字:汤姆”(当然没有引号)。这适用于程序化解决方案,但不适用于最终用户。使用部分名称在SharePoint中进行人员搜索

在SharePoint 2007中有没有一种方法可以让用户使用部分名称搜索人员?

回答

2

我发现这个解决方案对我们来说工作得很好。

将ContentEditor Web部件添加到目标页面并转到HTML编辑器按钮。添加以下HTML代码。它创建两个输入字段(名字/姓氏),然后创建一个查询,其中包含的搜索项作为属性搜索将调用全文搜索。

注意:您需要将搜索结果页面替换为适合您的配置的位置。

<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>