+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Search not working correctly

Search not working correctly

5 posts, 0 answered
  1. Pik Lee
    Pik Lee avatar
    142 posts
    Registered:
    13 Aug 2012
    02 Jul 2010
    Link to this post
     This issue has been solved. Thanks.
  2. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    05 Jul 2010
    Link to this post

    Pik, I would be really grateful for any suggestions you could provide for search results by role.  I have been woking on the same functionality for quite some time now.  I am especially curious about the part below, and getting the GUID of the page.  Then did you use this to check the permissions and display the resutling item depending on the users role? Did you get it all to work? Thank you.

    foreach (ResultItem customItem in CustomDataSource)
      {
         string value = customItem.Snippet;
         string pID = value.Substring(0, 36);
                                 
         var cmsManager = new CmsManager();
         ICmsPage page = (ICmsPage)cmsManager.GetPage(pID);
         PagePermission perm = new PagePermission(page);
         if (perm.CheckDemand(CrudRights.View))
             {
                  //Do something                             
             }
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    05 Jul 2010
    Link to this post
    Hi Laura,

    You have to create a new generic list of type ResultItem and exclude the items for which you do not have view permissions.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  4. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    05 Jul 2010
    Link to this post
    Yes thank you , like this I suupose..

    if (perm.CheckDemand(PageRights.View))

     

    {

     

     

     var contentInfo = new ResultItem();

     

     

     contentInfo.Title = customItem.Title.ToString();

     

     

     contentInfo.Snippet = customItem.Snippet.ToString();

     

     

     contentInfo.Url = customItem.Url;

     

     

     dataSource.Add(contentInfo);

     

     

     

     

     

    }

    however I am not always getting the UID back in the snippet. I saw to use the Title instead so have to figure that out....

     

    var cmsManager = new CmsManager();
    ICmsPage page = (ICmsPage)cmsManager.GetPage(ItemID);
      
    //// *** example//ICmsPage page = (ICmsPage)cmsManager.GetPage(new Guid("7c88a892-4be3-489-b4df-6ad9f0aa6aef"));
    //// *** getting error on the above line: System.ArgumentOutOfRangeException: Index and length must refer to a location within the string.
      
    //// *** sometimes the GUID doesn't come back in the snippet. Suggested using Title instead.
      
    PagePermission perm = new PagePermission(page);

    if (perm.CheckDemand(PageRights.View))

     

    {

     

    }

     

     

     

     

  5. Pik Lee
    Pik Lee avatar
    142 posts
    Registered:
    13 Aug 2012
    06 Jul 2010
    Link to this post
    Laura, you need to place the following in the search xml file.

    <

     

    field name="guid" weight="1" indexAttribute="" filterTag="guid" filterAttributes="" />

     


    Below is part of my code that filter the search results. Hope this helps.

    IList

     

    <ResultItem> filteredItems = new List<ResultItem>();

     

     

    foreach (ResultItem item in dataSource)

     

    {

     

    string value = item.Snippet;

     

     

    this.layoutCnt.ResultsStats.Text = value;

     

     

    string chkFirstValue = value.Substring(0, 1);

     

     

    string ID = value.Substring(0, 36);

     

     

    Guid ItemID = new Guid(ID);

     

     

    CmsManager cmsManager = new CmsManager();

     

     

    ICmsPage page = (ICmsPage)cmsManager.GetPage(ItemID);

     

     

    PagePermission perm = new PagePermission(page);

     

     

    if (perm.CheckDemand(CrudRights.View))

     

    {

    filteredItems.Add(item);

    totalItems2 = totalItems2 + 1;

    }

    }

    dataSource = filteredItems;

Register for webinar
5 posts, 0 answered