Configuring and customizing
SharePoint 2010 search
- Part 1:
Configure basic search
- Part 2:
Metadata and faceted search
- Part 3:
Tie in additional facets
- Part 4:
Customize the results
- Part 5:
Add a field to the advanced search filter
Part 1: Configure Search
1) Load Central Admin2) Click Manage Service Applications
3) Click New –> Search Service Application

4) Specify the
- Name
- Service Account
- App Pools
There are no real gotcha’s here.
5) Select the newly created service application and click ‘Manage’

6) Click content sources, drop the context menu down on ‘Local SharePoint sites’ and choose edit
7) Set Full and incremental crawl schedules and start a full crawl.
If you go back to your site (after the crawl completes!) you’ll get results.

So, that’s search results but that’s pretty dull right. So the next task is to show search facets.
Part 2: Metadata and Faceted
Search
) Go to your site settings and
select the Term Store Management option
2) Add a new Group, Term Set and Terms, if you have problems here make sure the account you are logged in is in the list of Term Store Administrators (page right) – even if you’re logged in as the farm admin. I’m using Customers as my term set as per:

3) Add site columns for the metadata we’ll add to the document content type. Go to Site Settings –> Site Columns and add a site column called Customer
4) Make the new site column a Managed Metadata type and select the relevant node of your term store ala:

Now we want to associate those columns with the document content type.
6) Back to Site Settings –> select Site Content Types, now click on the Document content type
7) Add the two metadata fields we just added to the content type and you should have something like:

8) Ok so we now have our new document type and we should (after the next crawl) see the effect of this in search results. So to force that go to central admin, manage the search application, select the default scope (if that’s when you have) and start a (full) crawl.
So, now when we search what do we see?
Well, the results are obviously the same but now SharePoint has automatically picked up one of our metadata fields and allowed a faceted search filter on that:

So, that’s nice but where is that other column? Basically SharePoint doesn’t add it because it’s a not a metadata field (there a refinement in the box to automatically pick these up), it also has almost infinite possible values and SharePoint wouldn’t know how to categorise those values in a way that would add value. In the next part we’ll add that Sales Potential Field as a facet.
Part 3: Tie in additional facets
Jump back into
Central Admin, from there manage your search application
2) Select the
Metadata Properties under the section “Queries and Results”
3) Click “New
Managed Property”
-
- Call the
property “SalesValue”
- Set the
type to “Decimal” (mapping to currency)
- In the
“Mappings to crawled properties” area search for the crawled field we
created earlier (NOTE: the field will have been renamed internally by
SharePoint because it’s a decimal it gets a text equivalent field and the
actual decimal value is placed in this newly named field)
Now we have
that field available to us in search we can go ahead and define how we should
use it. If you go back to your site and do a search you’ll be on the
results.aspx page and it’s this page we want to change…
1) Edit the
page
2) Edit the
“Refinement Panel” web part on the left hand side (toward the bottom of the
page) and expand the “Refinement” node.
3) VERY
IMPORTANT: Unclick the “Use Default Configuration” option!!!
4) Add XML
display the new managed property…
Now because the
new property is a decimal value there are a few things we want to do and some
just to be aware of. Firstly, we don’t just want to show the value itself
we will want to categorise the values into meaningful bands i.e. High Value
Medium Value, Low Value, we can do this quite easily but the thing to be aware
of is that most example you’ll see out there use a syntax like:
<CustomFilter CustomValue="Medium Value">
<OriginalValue>50000..99999</OriginalValue>
</CustomFilter>
That’s no good for
a decimal value because what search will do is apply that filter almost exactly
as it shows and because it’s comparing a decimal it’ll get all confused about
those dots in between the numbers! You get something like: “Property
doesn’t exist or is used in a manner inconsistent with schema settings.” –
you’ll also get that if you’ve come this far without creating the field as a
managed property. So what we’re going to do is specify a lower and upper
threshold for the original value. The full XML for the display of the
SalesValue field will now become:
<Category Title="Sales Potential" Description="Allows
refinement by saleable value"
Type="Microsoft.Office.Server.Search.WebControls.ManagedPropertyFilterGenerator"
MetadataThreshold="3" NumberOfFiltersToDisplay="4"
MaxNumberOfFilters="0" ShowMoreLink="True"
MappedProperty="SalesValue"
MoreLinkText="show more"
LessLinkText="show fewer" SortBy="Custom"
ShowCounts="Count">
<CustomFilters MappingType="RangeMapping" DataType="Numeric"
ValueReference="Absolute" ShowAllInMore="False">
<CustomFilter CustomValue="Second home">
<OriginalValue>500000..</OriginalValue>
</CustomFilter>
<CustomFilter CustomValue="New car">
<OriginalValue>200000..</OriginalValue>
<OriginalValue>..499999</OriginalValue>
</CustomFilter>
<CustomFilter CustomValue="Holiday">
<OriginalValue>100000..</OriginalValue>
<OriginalValue>..199999</OriginalValue>
</CustomFilter>
<CustomFilter CustomValue="Biscuits">
<OriginalValue>50000..</OriginalValue>
<OriginalValue>..99999</OriginalValue>
</CustomFilter>
<CustomFilter CustomValue="Coffee">
<OriginalValue>2500..</OriginalValue>
<OriginalValue>..49999</OriginalValue>
</CustomFilter>
<CustomFilter CustomValue="You owe us!">
<OriginalValue>..2499</OriginalValue>
</CustomFilter>
</CustomFilters>
</Category>
5) In the
“Filter Category Definition” box, copy out the contents to a useful editor
(Visual Studio works for me)
6) Combine the
XML snippet above with the XML that was already in the textbox, for reference I
added my XML just above the Managed Metadata column. Save the changes are
re-query.
Done! You
should now see something like the following and be able to refine search on the
facet we just created:
Part 4: Customize search results
1) Edit the
“Search Core Results” web part by editing the search results page
2) Uncheck the
“Use Location Visualization” option within the “Display Properties” node
3) Copy the
text out of the “Fetched Properties” text box and edit it to add out new field:
<Columns>
<Column Name="WorkId"/>
<Column Name="Rank"/>
<Column Name="Title"/>
.
.
.
<Column Name="SalesValue"/>
</Columns>
This will make
the property available (although when I tested it without the entry it still
worked!)
4) Now edit
the same web part (if you closed it down) and load the XSL Editor from
the “Display Properties” node and copy the XSLT out into an editor.
5) Add the
SalesValue to the search results by editing the XSLT. It quite a large
file but essestially you’re just looking for the “results” match. Now
you’ve found that you should be able to see the method that’s been employed to
render the results. I’m going to add a new template to output out
field. Here I’m just copying the string template with minor changes:
<!-- AJN: Additional output field starts here -->
<xsl:template name="DisplaySalesValue">
<xsl:param name="str" />
<xsl:if test='string-length($str) > 0'>
<b>Sales Value: $<xsl:value-of select="$str"
/></b>
</xsl:if>
</xsl:template>
.6) Now add a
call to that template to output the value at the end of the metadata area of
search results. To do this I’ve popped back up to the results match we
found earlier and directly after the file size output I’ve added a call to the
new template:
<div
class="srch-Metadata2">
<xsl:call-template
name="DisplayAuthors">
.
.
.
<xsl:call-template
name="DisplaySalesValue">
<xsl:with-param
name="str" select="salesvalue" />
</xsl:call-template>
<img
style="display:none;" alt=""
src="/_layouts/images/blank.gif"/>
</div>
And here’s an
example of the output:
Part 5: Add a field to the
advanced search filter
Finally lets make that Sales
Value property available in advanced search.1) Do a search and go to the advanced search page, edit the page and edit the “Advanced Search Box” web part…

2) Copy out the “Properties” XML to your favourite editor and add the property definition thus:
<PropertyDefs>
<PropertyDef Name="Path" DataType="text" DisplayName="URL"/>
.
.
. <PropertyDef Name="SalesValue" DataType="integer" DisplayName="Sales Value"/>
</PropertyDefs>
3) Then add a reference to the field
in the “All Results” set thus: <ResultType DisplayName="All Results" Name="default">
<KeywordQuery/>
<PropertyRef Name="Author" />
.
.
.
<PropertyRef Name="SalesValue" />
</ResultType>
Now that really is it, you should
now be able to do any kind of search (normal or advanced anyway!) and have
access to the managed properties and metadata fields we created:
Handy tips
The following XSLT will show you
all the XML that is returned from search so you can check that your properties
are being returned correctly:<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xmp><xsl:copy-of select="*"/></xmp>
</xsl:template>
</xsl:stylesheet>
Have a play around with the
refinement syntax, it’s quite smart and I have a feeling it’s going to come in
handy on coded applications!For example:
http://noonscape/Search/results.aspx?k=test&r=salesvalue>=”200000” salesvalue>”49999″http://noonscape/Search/results.aspx?k=sharepoint&r= salesvalue<=”10000000″ AND salesvalue>”500000″


No comments:
Post a Comment