+1-888-365-2779
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
    Registered:
    24 Sep 2015
    18 Mar
    Link to this post

    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

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