Is this there a way to programmatically set the query text or append additional KQL filtering to a Content Search Web Part

Is this there a way to programmatically set the query text or append additional KQL filtering to a Content Search Web Part

I am currently working on a SharePoint 2013 project that required the use of a Content Search Web Part with some additional KQL filtering added based on the role of the current user.  I found the following blog post that showed how to set the query text of a Content Search Web Part programmatically.


Creating my own custom content search web part did provide the desired results I was looking for, but I am still having issues.  I am using my new custom Content Search Web Part in conjunction with a Search Box and Search Refinement web parts.  When my page first loads, my BeforeSerializeToClientEventHandler is fired and I set the query text to produce the desired results.  The problem is when the search results are then altered by the associated search box or search refiner.  It seems that my query text, set in the initial page load, is lost and the BeforeSerializeToClientEventHandler is not fired.  Is this there a way to programmatically set the query text or append additional KQL filtering to a Content Search Web Part, when it is being refined by a Search Box or Search Refinement Web Part?  IĄ¯m not sure if the refinement is happening client or server side.

I found the answer to my problem.  I needed to set the DataProviderJSON property for my custom Content Search Web Part.  With this set, the refiners would yield the expected results.  The following link outlines how to set the DataProviderJSON property:http-://carepoint.blogspot.-co.-at/2013/04/setting-dataprovider-for.html

 

Copyright © 2007-2012 www.chuibin.com Chuibin Copyright