in

Dot Net Mafia

Group site for developer blogs dealing with (usually) .NET, SharePoint 2013, SharePoint 2010, Office 365, SharePoint Online, and other Microsoft products, as well as some discussion of general programming related concepts.

This Blog

Syndication

Archives

Corey Roth [MVP]

A SharePoint MVP bringing you the latest time saving tips for SharePoint 2013, Office 365 / SharePoint Online and Visual Studio 2013.

How to: Use the new Append Text to query property in CoreResultsWebPart to return documents only

One common thing people have asked for in the MSDN Search Forums a lot (besides the obvious things like wildcard search) is the ability to get results that contain just documents.  In this case, people just want documents, no list items or folders, or sites, or anything like that.  It wasn’t terribly difficult to do in MOSS 2007 and I even wrote a post about it, but now there is another way this can be done.  We’ll be looking at the CRWP in more detail pretty soon, but I thought this would be something quick to mention.  Consider the following search results.

EnterpriseSearchResultsAccountingAll

From the screenshot above you should see that I have documents and list items returned in my search results.  We want to filter that down to just documents.  Before we had to create a scope to handle it.  Now we can use the new Append Text to Query property.  Take a look.

CoreResultsWebPartAppendQuery

This new textbox allows you to append whatever you want to what the user searched for.  In my case I am adding IsDocument:”1” to the query to restrict our search to documents, but you could add whatever you can think of to your query here.  After adding it, here is what my search results look like.

EnterpriseSearchResultsAccountingDocuments

My results only contain documents now.  This may just be an issue with Beta 2, but it causes the record count to be incorrect and the pager to think there are additional pages.  Anyhow, I think this property will be quite useful.  This functionality was actually already sort of present in MOSS 2007.  There is an undocumented query string parameter, a, that does this same functionality.  I stumbled upon it once when I was using reflector on the CRWP.

Comments

 

Monisha said:

Hi,

First of all, let me tell u, all the posts in this site are really helpful.. I have a query.

Is this "AppendTextToQuery" field can be used only for users who are having "Full control" access? I'm currently working with the same, and not able to get the filtered result for Users having access below "Full control".. Could you please let me know if I'm wrong?? Or let me know how to make it work for Users having below "Ful control" access..

December 7, 2010 3:52 AM
 

CoreyRoth said:

@Monisha well it should work for any user.  When you are crawling, make sure your default content access account does not have administrator permissions as that might cause issues in your search results.

December 8, 2010 9:12 AM
 

Rajner said:

Hi

I'm trying to use the Append Text To Query to filter on a datefield like  -  ItemExpiryDate>DateTime.Today where "ItemExpiryDate" is metadata property mapped to the site column. I want to get only those items which have an expiry date greater than today's date. I get an error like "Property doesn't exist or is used in a manner inconsistent with schema settings"

If I give a date directly, like ItemExpiryDate>"1/1/2011" it works

January 30, 2011 11:24 PM
 

CoreyRoth said:

@Rajner I'm afraid the Append Text To Query property doesn't allow you to use code in it such as DateTime.Now.  What you could do is inherit from CoreResultsWebPart and override the property that way though.

January 31, 2011 9:21 AM
 

Rajner said:

Thanks for the reply. I didn't get your reply clearly. Can I extend and expose that as a toolpart filter very similar to append text to query?

Currently I'm doing the filter in XSLT. Is that ok?

January 31, 2011 11:49 PM
 

CoreyRoth said:

@Rajner I think you'll need to write a new C# class that inherits from CoreResultsWebPart to achieve what you want.  I don't think XSLT will help.

February 4, 2011 10:34 AM
 

lili said:

hi i am triying to filter only list items and documents, where can i find the text to query?, e.g. you used IsDocument:”1” how did you get that one? thanks :)

February 21, 2011 1:29 PM
 

CoreyRoth said:

@lili This post has some more handy search keywords you might want be interested in.

www.dotnetmafia.com/.../some-handy-keywords-you-might-find-useful-in-sharepoint-enterprise-search.aspx

February 21, 2011 1:51 PM
 

Mimi said:

I have troubles to get NOT working, any help on that?

e.g not(mp:('value'))

March 14, 2011 5:28 AM
 

CoreyRoth said:

@Benjamin I think I tried that before and the syntax doesn't come out to be quite right so it doesn't work.  Did it work for you?

February 7, 2012 12:00 AM

Leave a Comment

(required)  
(optional)
(required)  
Add

About CoreyRoth

Corey Roth is an independent SharePoint consultant specializing in ECM, Apps, and Search.
2012 dotnetmafia.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems