Monday, March 16, 2009

Building Windows SharePoint Services Search Queries

Search in Windows SharePoint Services supports three types of search syntax for building search queries:

· Keyword Query syntax (search terms are passed directly to the Search service)
· SQL syntax (extension of SQL syntax for querying databases)
· URL syntax (search parameters are encoded in URL, and posted directly to the search page)

Keyword Query syntax

You can pass two types of terms in a Windows SharePoint Services Search keyword query:
· Keywords (the actual query words for the search request)
· Property filters (the property constraints for the search request)
e.g Keyword site:http://marketing http://customersupport/

Site and URL are the Managed Properties used in Search.

The filtering Search results based on the web sites and sub sites can be done thru OOB search itself by giving the filter site keyword (Note: site is a Managed property). SharePoint allows searching content based on one or more managed property. If the search keyword is “Test”, we need to append the web site URL along with the search keyword in the OOB Search Web part to get the results Test site: http://servername/US. OOB web part provides this functionality and the site filter is appended along with the Search keyword.

Otherwise, the url is given like this http://servername/SearchCenter/Pages/results.aspx?k=Test.

In the above URL, key word and site are used to filter the results.
Where http://servername/SearchCenter/Pages/results.aspx is the Search results page

Mapping Crawled Properties to Managed Properties
To make a crawled property available for the Search experience—to make it available for Search queries and display it in Advanced Search and search results—you must map it to a managed property. You can map multiple crawled properties to a single managed property or map a single crawled property to multiple managed properties. If a managed property has multiple crawled properties mapped to it, and a document contains values for more than one of the crawled properties, the order in which the properties are mapped and their priority determine the managed property’s value.

Multiple Property Filters in Enterprise Search
Enterprise Search in Microsoft Office SharePoint Server 2007 keyword syntax supports the use of multiple property filters within the same query. You can use either multiple instances of the same property filter or different property filters.
Using the Same Property Filter
In this scenario, the keyword query is based on a union of the property filters. This is equivalent to the OR operator used in SQL search syntax.
For example, if you specify the following property filters for a keyword query, both the http://marketing/and http://customersupport/ sites are included in the search:
site:http://marketing/ site:http://customersupport/

Using Different Property Filters
In this scenario, the keyword query is based on an intersection of the property filters. This is equivalent to the AND operator used in SQL search syntax.

For example, if you specify the following property filters for a keyword query, all content authored by John Smith from the http://marketing site is included in the search:
site:http://marketing/ author:"John Smith"

SQL Syntax Examples
Search in Windows SharePoint Services provides support for constructing complex search queries through the SQL syntax. Some examples of what is available when using SQL syntax for search queries include the following:
· Comparison operators, such as ">", "<", or · Multiple logical operators, such as AND, OR, and NOT.

1. Finds relevant results containing the keyword SharePoint.
SELECT WorkId,Path,Title,Write,Author,HitHighlightedSummary, HitHighlightedProperties,CollapsingStatusFROM Scope()WHERE FREETEXT(defaultproperties, 'SharePoint') ORDER BY Rank Desc

2. Finds relevant results containing at least one of the keywords SharePoint and Search. SELECT WorkId,Path,Title,Write,Author,...FROM Scope()WHERE FREETEXT(defaultproperties, 'SharePoint Search') ORDER BY Rank Desc

3. Finds relevant results containing both the keywords SharePoint and Search.
SELECT WorkId,Path,Title,Write,Author,...FROM Scope()WHERE FREETEXT(defaultproperties, '+SharePoint +Search') ORDER BY Rank Desc

4. Finds relevant results containing the exact phrase SharePoint Search.
SELECT WorkId,Path,Title,Write,Author,...FROM Scope()WHERE FREETEXT(defaultproperties, ' "SharePoint Search" ') ORDER BY Rank Desc

5. Finds relevant results containing both the keywords SharePoint and Search but not the keyword WSS.
SELECT WorkId,Path,Title,Write,Author,...FROM Scope()WHERE FREETEXT(defaultproperties, '+SharePoint +Search -WSS') ORDER BY Rank Desc

6. Finds relevant SharePoint results authored by persons named John.
SELECT WorkId,Path,Title,Write,Author,...FROM Scope()WHERE FREETEXT(defaultproperties, 'SharePoint') AND CONTAINS(Author,' "John" ')ORDER BY Rank Desc

7. Finds relevant SharePoint results modified within the last 30 days. SELECT WorkId,Path,Title,Write,Author,...FROM Scope()WHERE FREETEXT(defaultproperties, 'SharePoint') AND Write<=DATEADD(DAY,30,GETGMTDATE())ORDER BY Rank Desc.

Configuring sharePoint Search step by step is available here

Customizing core results web part is avaialble here

No comments: