Try Now
More in this section

Forums / Developing with Sitefinity / Can Search service return only published search results

Can Search service return only published search results

3 posts, 0 answered
  1. Gary
    Gary avatar
    2 posts
    24 Sep 2015
    18 Mar 2016
    Link to this post


    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?




  2. Dimitri Cools
    Dimitri Cools avatar
    80 posts
    19 Jun 2017
    21 Mar 2016
    Link to this post

    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.

    Dimitri Cools
    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
  3. Gary
    Gary avatar
    2 posts
    24 Sep 2015
    22 Mar 2016 in reply to Dimitri Cools
    Link to this post
    Perfect, thanks Dimitri.
3 posts, 0 answered