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

Forums / General Discussions / Search News

Search News

8 posts, 1 answered
  1. Asif
    Asif avatar
    110 posts
    Registered:
    18 Nov 2010
    10 Jan 2011
    Link to this post
    Hi,
    I am currently using below code to search news. And it is working pretty fine. But this code only matches the exact keyword with the Title of News. For example if the News Title is "News 1" and if the keyword is "News 1" then it will show only one result which is correct but if the keyword is "News" then it wont show any result. However, it should show the result "News 1". Also if the description of "News 1" is "News 1 xyz ...." and if the keyword is "xyz" then it should show the "News 1" in result. Can you please guide me how to achieve that? I know I need to modify the below code some show.

    filter.Add(new Telerik.Cms.Engine.MetaSearchInfo(Telerik.Cms.Engine.MetaValueTypes.ShortText, "Title", Keyword.Text.ToString()));
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    11 Jan 2011
    Link to this post
    Hello Asif,

    The MetaSearchInfo has an overload which accepts parameter- SearchCondition. The SearchCondition is an enum where you can use the following members.


       

    Greetings,
    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
  3. Asif
    Asif avatar
    110 posts
    Registered:
    18 Nov 2010
    11 Jan 2011
    Link to this post
    Hi, thanks for the help I am almost there. the issue I am now facing is if any user insert any text then my search functionality should look into the News description as well and I am not sure if there is any meta key for News Description or News Content that means I can't use IMetaSearch for this purpose. Maybe I should use LINQ. But, do you know how to use LINQ for News? I am trying the below code but it is giving me error that I can't use "Where" in ILIST. Please help.
    ContentManager contentManager = new ContentManager("News");
    IList listOfContentItems = contentManager.GetContent();
    IList  getNews = listOfContentItems.Where(p => p.Title.Contains(Keyword.Text));
            repeater.DataSource = getNews;
    repeater.DataBind();
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    11 Jan 2011
    Link to this post
    Hi Asif,

    Use the code below

    ContentManager contentManager = new ContentManager("News");
          IList listOfContentItems = contentManager.GetContent();
          IList getNews = listOfContentItems.Cast<IContent>().Where(p => p.GetMetaData("Title").ToString().Contains(Keyword.Text)).ToList();


    Regards,
    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
  5. Asif
    Asif avatar
    110 posts
    Registered:
    18 Nov 2010
    12 Jan 2011
    Link to this post
    Hi Ivan,
    Thanks for the help. I can only match the keyword with News title using your code but I need to look into the News Content / Description as well. So, what should I do to look the keyword into content. Should I do something ?? but I am sure there is no "content" key in metadata. Any help?

    IList getNews = listOfContentItems.Cast<IContent>().Where(p => p.GetMetaData("Title").ToString().Contains(Keyword.Text) || p.GetMetaData("Content").ToString().Contains(Keyword.Text)).ToList();
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    12 Jan 2011
    Link to this post
    Hello Asif,

    Content is a property of IContent item and you should be able to access it in the link expression directly.

    Best wishes,
    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
    Answered
  7. Asif
    Asif avatar
    110 posts
    Registered:
    18 Nov 2010
    14 Jan 2011
    Link to this post
    Thanks Ivan for your help. I am now using below code to achieve me goal. It is working fine. But one issue. If the news heading is "News" and keyword is "News" then it will work perfectly but if the keyword is (news) - All small - or keyword is (NEWS) - All Caps - then it is not displaying result. Please tell me is there any way to control the caps issue??


    IList getNews = listOfContentItems.Cast<IContent>().Where(p => p.GetMetaData("Title").ToString().Contains(Keyword.Text) || p.Content.ToString().Contains(Keyword.Text)).ToList();
  8. Asif
    Asif avatar
    110 posts
    Registered:
    18 Nov 2010
    14 Jan 2011
    Link to this post
    I am using this now and it is working fine. Thanks for the help.

    IList getNews = listOfContentItems.Cast<IContent>().Where(p => p.GetMetaData("Title").ToString().ToLower().Contains(Keyword.Text.ToLower()) || p.Content.ToString().ToLower().Contains(Keyword.Text.ToLower())).ToList();
Register for webinar
8 posts, 1 answered