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

Posted Thursday, March 11, 2010 3:11 PM by CoreyRoth

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

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

Tuesday, December 7, 2010 3:52 AM by Monisha

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..

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

Wednesday, December 8, 2010 9:12 AM by CoreyRoth

@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.

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

Sunday, January 30, 2011 11:24 PM by Rajner

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

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

Monday, January 31, 2011 9:21 AM by CoreyRoth

@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.

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

Monday, January 31, 2011 11:49 PM by Rajner

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?

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

Friday, February 4, 2011 10:34 AM by CoreyRoth

@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.

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

Monday, February 21, 2011 1:29 PM by lili

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 :)

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

Monday, February 21, 2011 1:51 PM by CoreyRoth

@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

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

Monday, March 14, 2011 5:28 AM by Mimi

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

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

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

Tuesday, February 7, 2012 12:00 AM by CoreyRoth

@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?

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

Wednesday, August 13, 2014 11:57 AM by Dhaval

Hi I want to know, what text/keyword/value should I use for Append Text To Query to get results from specific site collection ?

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

Monday, August 18, 2014 12:29 PM by CoreyRoth

@Dharval Use site:"server/sitecollection".

Leave a Comment

(required) 
(required) 
(optional)
(required)