Can Search service return only published search results

Posted by Community Admin on 04-Aug-2018 17:11

Can Search service return only published search results

All Replies

Posted by Community Admin on 18-Mar-2016 00:00

Hi,

We are using the search service to search against a dynamic module:

var service = ServiceBus.ResolveService<ISearchService>();

var compiledQuery = query.BuildQuery(string.Concat(term, "*"), new string[] "RecipeName" );
compiledQuery.IndexName = "our-index";

var results = service.Search(compiledQuery);

 

While it does return an IResultSet object, we are being forced to retrieve each search result again to ensure it is published content.  Unfortunately, we taking a performance hit because of this extra work:

 

foreach(var result in results)

var recipe = dynamicManager.GetDataItem(recipeType, Guid.Parse(result.Fields.SingleOrDefault(f => f.Name == "Id").Value.ToString()));

if(recipe.IsPublished() && recipe.Visible)

//other stuff

 

Is there a way to specify in the compiledQuery variable that I want to return only Published content?

 

Thanks,

Gary

Posted by Community Admin on 21-Mar-2016 00:00

Hello,

The search service only returns published items as only the published items are indexed.
There is no need to perform additional queries to ensure that.

For you information, here's a KB article that handles about
How to search programmatically in Sitefinity

Should you continue to have issues with this, please provide additional details including screenshots that demonstrate the behavior in order for us to test.

Regards,
Dimitri Cools
Telerik

 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 22-Mar-2016 00:00

Perfect, thanks Dimitri.

This thread is closed