Showing posts with label Search. Show all posts
Showing posts with label Search. Show all posts

Friday, May 6, 2016

Mapping SharePoint 2013 Crawled Property to Managed Property for Search-driven Applications

Search-driven applications are a great way to utilize the powerful SharePoint search features to surface content. SharePoint offers sleek methods to extend search to create search-based solutions and applications.
When you use the Search Results web part to display the search-driven content, you might want to sort or filter the search results. These results can be sorted and filtered on managed properties. However, you have your data fields already in-use as crawled properties. To get the Search Results web part to work with your crawled properties, you need to map those crawled properties to managed properties. You can do this from the Site Collection Settings by going to Search Schema.
If you want to do this programmatically, the following PowerShell script will do it for you.

How to use the script:

  • Save the script as “MapCrwlProp2MgdProp.ps1”
  • Open PowerShell and go to the directory where the script is saved.
  • Modify the parameters and run the following command “.\MapCrwlProp2MgdProp.ps1 -CrwProp “Crawled Property” -MgdProp “ManagedProperty” -DataType 2”
The script checks if the Managed Property exists or not. If it doesn’t exist, it creates the managed property and maps it to the crawled property, simple eh!

<# Example: .\MapCrwlProp2MgdProp.ps1 -CrwProp "Crawled Property" -MgdProp "ManagedProperty" -DataType 2 
Parameters: DataType 1 - Text
2 - Integer
3 - Decimal
4 - Date & Time
5 - Yes/No
6 -
Double precision float
7 - Binary 
CrwProp - Crawled Property 
MgdProp - Managed Property 
Variables:
$SSAName = Search Service
Appication Name. By default, it is "Search Service Application". If it is different in your case, please change it in the script.
$ManagedMetadataCategory = Managed Metadata Category. By default, it is "SharePoint". If it is different in your case, please change it in the script. #>

Param(
[Parameter(Mandatory=$true)]
[string]$DataType,

[Parameter(Mandatory=$true)]
[string]$CrwProp,

[Parameter(Mandatory=$true)]
[string]$MgdProp
)

$SSAName = "Search Service Application"
$ManagedMetadataCategory = "SharePoint"

Function MapManagedProperty ($CrwProp, $MgdProp, $DataType)
{
$ssa = Get-SPEnterpriseSearchServiceApplication -Identity $SSAName
$cat = Get-SPEnterpriseSearchMetadataCategory -SearchApplication $ssa -Identity $ManagedMetadataCategory
$cct = Get-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication $ssa -Name $CrwProp -Category $cat

If ((Get-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $ssa -Identity $MgdProp -ErrorAction SilentlyContinue) -eq $null)
{
Write-Host "Managed Property" + $MgdProp + "does not exist. The script will attempt to create it."
$mct = New-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $ssa -Name $MgdProp -Type $DataType -Queryable $true
}

New-SPEnterpriseSearchMetadataMapping -SearchApplication $ssa -CrawledProperty $cct -ManagedProperty $MgdProp
}

#Ensure SharePoint PowerShell snapin is loaded
if((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null){
Add-PSSnapin Microsoft.SharePoint.PowerShell
}

MapManagedProperty $CrwProp $MgdProp $DataType

Write-Host "Property mapping is completed" -ForegroundColor Green

Tuesday, October 16, 2012

People Search in SharePoint 2010

People Search Box Web Part in SharePoint 2010



People Search is one of the great and useful features of SharePoint 2010. By using people search feature of the SharePoint 2010 users can find their co-workers not just by their names, by their hobbies, interests, department, job title, knowledge and expertise as well.

In this blogbost I would like to show you how you can enable the SharePoint People Search web part and customize it. So let's get started.

If you have a brand new SharePoint 2010 farm or you have not configure the search in your SharePoint 2010 platform, this is something you need to take care first. Here is how:
  • You need to visit the SharePoint central admin and locate your content sources under the search service application by clicking "Application Management", "Manage Service Applications", "Search Service Application" and "Content Sources".
  • If this is a new instance you'll probable have one item called "Local SharePoint sites". Please click this content source and edit.
  • In this page you need to make sure sps3://MySiteRoot item is in your start addresses list. 
  • You alse need to scheudle the full and incremental crawl in this page and check "Start full crawl of this content source" before clicking "Ok.
  • At this time you'll see the following screen:
Once this is completed, now you can insert SharePoint 2010 People Search Box web part into any page you desire. In my example I am placing the web part right into the SharePoint home page. 
  • First you will edit the page by going "Site Actions", "Edit Page"
  

















  • Then you can select "Insert", "Web Part" by going "Editing Tools" ribbon.
  • You will chose "People Search Box" web part under the "Search" category of web parts. 


  • Once the People Search Box web part is added tot he page then we can configure the web part selecting "Edit Web Part" from the web part drop down menu.
  • While you are editing the web part, you can have scopes drop down menu and select which search scope you'd like to use and in which format. In this blog post since I will be showing the People Search, I am not including the "Scopes" drop down menu.
  • You can configure the Query Text Box, by assigning a label, fixing it's size, and defining the text box prompt string.


















  • Query suggestions is a great way to display keyword suggestions to end-user while they are typing the query. These suggestion will be created automatically by SharePoint automatically based on certain number of click-throughs. There is a daily timer job scheduled to compile the suggestions. It is called "Prepare query suggestions" timer job and it is turned on by default.  If you are testing the keyword suggestions, you probably don't have any suggestion compiled yet. You can add these suggestions manually with power shell scripts. here is an example:

$searchapp = Get-SPEnterpriseSearchServiceApplication -Identity "Search Service Application"
New-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $searchapp -Language En-Us -Type QuerySuggestionAlwaysSuggest -Name "Jeff Armstrong"
New-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $searchapp -Language En-Us -Type QuerySuggestionAlwaysSuggest -Name "John Smith"
New-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $searchapp -Language En-Us -Type QuerySuggestionAlwaysSuggest -Name "Jennifer McDonald"
Start-SPTimerJob -Identity "prepare query suggestions"


  • There are many options to configure in miscellaneous section of the SharePoint People Search Box web part. Please refer to this TechNet article for further configuration options: Change properties for the Search Box Web Part (SharePoint Server 2010)
  • Once it is configured you can save the web part and save and check-in the page you are editing. This is how it will look like on the page: 




If you have done everything correctly and you have SharePoint publishing features enabled you will get a "404-Page not found" error because "peopleresults.aspx" does not exist in the Site Pages library. There are a few ways to workaround this issue. One of them is to create people results page manually. which is detailed in my other blog post called "People Search Results Return 404 - peopleresults.aspx is missing."
Here is how your results page will look like:




People Search Results Return 404 - peopleresults.aspx is missing.

People Search Results Return 404 - peopleresults.aspx is missing.


If you've turned on SharePoint publishing features and used a publishing page to house your people search web part, you got an HTTP 404 Page Not Found error.

If you can delete the "Basic Search Center" and create a new "Enterprise Search Center" you can resolve the issue. However if it is not your intention to create an Enterprise Search Center you can create th epeoplesearch.aspx page manually. Here is how:


  • Please create a new page by going "Site Actions", and "New Page"


  • You need to call this page "peopleresults"
  • This action will create a new page called "peopleresults.aspx" in the site pages liblary.
  • I suggest that you should create a basic two column 1 row table here. First column will host the search filter web part and second one will show the people search results. 
  • Please select Insert -> Table -> 2x1 Table.
  • Set the first column width to 150 pixels


  • Please locate you cursor in the first column and add "People Refinement Panel" web part by going "Editing Tools" -> "Insert" -> "Web Part" -> "People Refinement Panel".

  • Now you can locate you cursor in the second column do the same thing for "People Search Core Results" web part by going "Insert -> Web Part" under "Editing Tools"

  • You can remove the table borders while the cursor is in the table by going to "Table Tools" -> "Design" -> "Styles" -> "Table Style 1 - Clear". Here what you will get after:

  • Now you can save and close the page. At this stage the results page will show nothing which is normal. However if you do a people search you will get following result: