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.

Configuring contextual search to use search center

I’ve never been a fan of the way contextual search is handled in SharePoint out-of-the-box.  By default, SharePoint has contextual searches go to OSSSearchResults.aspx.   If you aren’t familiar with the term contextual search, you might be familiar with the This Site or the This List search scope options that you see in the search drop down list.

ContextualSearch

The reason I don’t like OSSSearchResults.aspx (besides all of the S in the page name) is that it is an application page and is generally considered not customizable.  This means if you want to configure how results are displayed or the refinement panel, you really can’t directly (without leaving yourself in an unsupported state).  You can make a copy of it and then make customizations, but that is a lot of effort for something so simple. 

I understand why SharePoint uses this page by default though.  The first reason is that SharePoint Foundation does not have a Search Center site template and it needs some place to render search results.  Secondly, even if you have SharePoint Server, you may not have created a search center.  Therefore, it uses this page by default so that search will work without any major configuration.

We want to customize what is on the contextual search page though.  What you can do is reconfigure the Site Collection Search Results Page URL to point to your search center.  We can find this setting in the Search Settings page of your site collection settings.  I talked about these settings in the past.  When you go to this page, you will see that the URL configured is /_layouts/OSSSearchResults.aspx.

SiteCollectionSearchSettings3

We simply change this to the URL of the results.aspx page in your Search Center.  Now, typically I install my search center on a URL such as /Search or /SearchCenter.  Determine what your URL is or go create a search center using the New Site menu.  In my example, we'll use /search.  You will find the results.aspx page in the Pages library, so the full URL we want is /Search/Pages/Results.aspx.  You can also determine this URL by going to your search center and performing a search.  When you enter the URL, leave out the server name.

SiteCollectionSearchSettingsCustomSearchCenter

Once you have finished, we can test our contextual search from any site or document library.

ConextualSearchResults

As you can see, our search results are now in the Search Center and we have things like people search showing up.  However, the results only contain the contextual information from the subsite.  Now, I can customize this page as needed.  The CoreResultsWebPart actually uses two extra query string parameters to make this happen.  The cs parameter has the contextual scope name, This Site.  The u parameter specifies which URL to limit the results to.  As always, the k parameter contains the query itself.   This is a simple customization to implement and I highly recommend it if you want to customize your contextual search results.

Comments

 

Mikael Svenson said:

Great read!

How would you best go about to provide a link on the search center which takes you back to where your search originated from? And is there a way to display which context your are searching in without doing custom development on the search result page?

December 10, 2010 7:07 AM
 

svet said:

Hi, I always see NO result in contextual search... any news ?? thanks

February 3, 2011 7:09 AM
 

CoreyRoth said:

@svet If contextual search is not working I would go back and verify your alternate access mappings first.  I would also try testing results on your site using the site keyword and a URL.  If it works correctly, you should see results.  If you have a bigger issue, it won't return results.

February 4, 2011 10:37 AM
 

CoreyRoth said:

@Mikael Sorry for the late reply, I didn't see your comment come through.  Yes, you identified the two common issues with putting your results through the search center.  I think both are going to require a bit of customization to the search center master page (or at the least adding a web part).

February 4, 2011 10:38 AM
 

Chitta said:

Great article,

I am having a strange issue here. Some time results are showing and sometime not. I have to refresh several time if results are not coming. some time navigators are coming but no result and vice versa. what may be reason?

May 13, 2011 3:03 PM
 

CoreyRoth said:

@chitta Hard to say.  Are you getting any errors when it occurs?  Does it occur when searching from a particular site or list?

May 16, 2011 2:16 PM
 

Nick Chokas said:

Great article...it helped me a lot.  However, when I go into any of the sub-sites and do a search using "This Site: test", no results show up.  

On the other hand, doing a search using "All Sites" works perfect.

Any ideas?  :-S

May 18, 2011 10:01 AM
 

CoreyRoth said:

If the contextual scope (this site) doesn't work I would start by verifying that your alternate access mappings are correct.  If they are not configured, it can prevent contextual search from working.

May 19, 2011 8:53 AM
 

Matt Herring said:

Corey - Can you provide any details or references to resolving the issue Mikael Svenson brought up?  That's the number one reason I don't use a search center.  The users get lost and the back button has some strange results sometimes.  Thanks.

June 13, 2011 3:28 PM
 

CoreyRoth said:

@Matt Most people tend to just re-implement the branding they apply to v4.master to a form that actually works with minimal.master.  This gives the user the ability to click elsewhere on the site.

June 20, 2011 4:12 PM
 

Vipin said:

Corey I have my alternate access mapping correct and get the right results for All Sites Search using search center and the same for this site gives no results. I also tried for this list, same results are not popping up. Custom Search scopes are working but Contextual searches are not working and we need both for our project. Please let me know if ou ever faced the same situation. Thanks in advance...

October 5, 2011 7:22 AM
 

CoreyRoth said:

@vipin The issue for me almost always seems to be related to the AAM. You may want to look at how you have them set up.  Typically, I set the FQDN to the default AAM and then crawl that same URL.  You can add other mappings for the server name, etc.

October 17, 2011 9:34 PM
 

Veerendra said:

Corey- i have the same problem what Vipin has mentioned. but on the server windows foundation search service is not running.Is because of that the site scope will not resturn results?

October 28, 2011 6:10 AM
 

Jeremy said:

When I attempt to do this the url is always wrong so I get a 404 error on a search query.

I know the full path to the page is myserver.mycompany.com/.../SearchResults.aspx so I change the site collection search results page to /_catalogs/SearchResults.aspx

This results in the url  myserver.mycompany.com/.../SearchResults.aspx

When I make the search results page /sites/mysitecollection/_catalogs/masterpage/SearchResults.aspx

This results in  myserver.mycompany.com/.../SearchResults.aspx

I just can't win here. What am I missing?

November 7, 2011 1:13 PM
 

CoreyRoth said:

The search service should not affect it in this case.  Check your alternate access mappings and the URl you are using to crawl on the content source.

November 7, 2011 8:37 PM
 

Nikhil said:

Excellent information,

Configured contextual scope same way as suggested above. But i have a peculiar issue when i redirect my queries to another FAST farm the contextual scope does not display any results.  Both the FARMS have same document counts.

Can you let me know , what could be the issue here ?

November 29, 2011 12:47 AM
 

CoreyRoth said:

@louis Your content source should be configured to use the default alternate access mapping.

December 7, 2011 8:45 PM
 

CoreyRoth said:

@Nikhil not sure what the cause would be there.  

December 7, 2011 8:52 PM
 

Ivan said:

I have set this up at one of my clients.

The only issue that I see is that if the user changes the search term and resubmits, the context disappears. Is there any way around this?

January 25, 2012 6:12 PM
 

markus said:

Hi, this works fine.

But if you configure in the search box of the result site under scopes "show and default to contextual scope" only the scope "this site: xxxx"  works for the next search. The scope "this list: xxxx" will not works for the next crawl instead of this he put "this site: search site" in the scopes dropdown...Any ideas?

February 1, 2012 8:13 AM
 

CoreyRoth said:

@Markus I don't have a good solution for that.  The reason it doesn't work is because the site has changed and therefore the context has changed as well.

February 6, 2012 11:52 PM
 

bnurick said:

I would like to see an answer to Ivan's & markus's issue, as I have the same (as everyone will the way this works).  The context is in fact lost on re-search, which really confuses the user.

I started down the path to edit the target search results page, to retain the contextual scope, which eventually messed up All Sites searching, because it defaulted to the Search Site Scope (hah, one issue for another!).

I then reviewed how the default osss context page works, and discovered I was basically re-building that page!!!

So, I am looking for the best practice here, since this behavior can confuse end-users.  

I think the answer here is, you create ANOTHER search page under Search Center, used just for contextual searching.  This way, you set the Search Box to use the contextual scope sent to the page, which will be retained, but you will no break SCOPED searches (All Sites, custom) since they target the other page.

Those are my thoughts.

February 10, 2012 7:52 PM
 

Rob Garrett said:

Hi Cory,

Aby idea how to get this working in SP2013? I changed the search settings for my site and site collection to use search center - I even waited the 30 minutes SharePoint tells you to wait (is there a timer service?)... yet, search this site in a team site always uses OSSSearchResults.aspx

Thanks for any help

R.

September 1, 2012 4:04 PM
 

CoreyRoth said:

@rob I've noticed the same thing in 2013.  I've also been looking at the new global setting that you can set in the search center.  It never changes anything.  I suspect it may be a bug.

September 10, 2012 8:36 AM
 

Giorgos Arc said:

@Rob, @Corey

I had the same issue in 2013. I resolved it by opening a browser at the server as an administrator (Run as...).

That allowed me to uncheck the "use the same results page settings as my parent" and type the Search Center results page.

May 28, 2013 9:21 AM
 

CoreyRoth said:

@Giorgos Arc good tip!

July 16, 2013 11:03 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