Restricting Search Results to contain only List Items / Documents


A very common request that comes up every now and then is to omit views, sites, lists/libraries etc. from Search results and only show list items/documents.

For example, in my test environment, if I search for a term “SharePoint“, I get 23 search results. Some of the items in the search results are site names or view names as shown below –

While not questioning the value or validity of these items in the search results, sometimes it may be necessary to make sure only documents or list items are included. So if I re-submit my search for SharePoint, but this time by suffixing a property called isDocument, I get only 14 items returned in the results. All those 14 items are documents. I have a list item in the Task and Announcements list which contains the word SharePoint in its Title, but those have been omitted as well.

If I alter my query to include a property called contentclass having a value starting with STS_ListItem, I get back 16 items. Two additional list items (one from the Announcements and the other from the Tasks list) are now present in the search results.

So achieving this was pretty simple, but how do you know what properties to include in your search and what values to assign to them. This is where you need to inspect the raw xml returned by the Query Service. The raw xml gives us a wealth of information related to the search results. From the XML I can see a list of managed properties returned and this is how I can take advantage of them to limit the information returned from search.

In case you are interested in knowing how to get search results information in raw xml format, refer to my blog post – Viewing Search Results in raw XML Format.

If you are not comfortable telling your end-users to always include a property in their search queries, you could add the property name:value as an additional query term.

  1. To accomplish this, edit the Search Box webpart.
  2. Under the Query Text Box section, specify the property name:value in the Additional query terms property. Uncheck the Append Additional terms to the query checkbox to hide this additional query term from the end-user by not having it echoed in the Search Box when the page is refreshed.

  1. Save and Close the page. Now when I search for SharePoint, even without specifying any other search limiter, only documents matching the search term are displayed in the results.

     

Advertisements

3 Responses to Restricting Search Results to contain only List Items / Documents

  1. Said says:

    interesting, thank you.

  2. Quality content is the secret to interest the viewers to go to see the site, that’s what this web site is providing.

  3. Helpful info. Lucky me I found your site by chance, and I am surprised why this twist of fate didn’t took place in advance!

    I bookmarked it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: