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

Forums / Bugs & Issues / Find news by title, case insensitive

Find news by title, case insensitive

7 posts, 0 answered
  1. Olivier
    Olivier avatar
    57 posts
    Registered:
    09 Jul 2010
    27 Oct 2011
    Link to this post
    Hi,

    Im trying to search news items by title.

    We already did this for documents, so I tried the same way, which is case insensitive:

    var news = App.WorkWith()
     .NewsItems()
     .Publihed()
     .Where(n => n.Title.IndexOf(myStringFilter, StringComparison.OrdinalIgnoreCase) > -1);

    Sadly, I get the following error at runtime with this piece of code:
    Method 'IndexOf' is not supported on the 'Telerik.Sitefinity.Model.Lstring' type.

    So I tried to use the Value of the Lstring:

    var news = App.WorkWith()
     .NewsItems()
     .Publihed()
     .Where(n => n.Title.Value.IndexOf(myStringFilter, StringComparison.OrdinalIgnoreCase) > -1);

    But now, I have this error, at runtime again, which seems to be the opposite of the first one:
    Property 'System.String Value' is not defined for type 'System.String'

    Both pieces of code compiled...

    Can you please enlighten me on this matter ?

    Thank you.

    Olivier
  2. Victor Velev
    Victor Velev avatar
    1345 posts
    Registered:
    06 Jul 2015
    01 Nov 2011
    Link to this post
    Hello Olivier,

    You can use ToLower() to find the titles. Here is a sample code:

    public void findnews(string myStringFilter, string myStringFilter2)
         {
             var news = App.WorkWith()
              .NewsItems()
              .Publihed()
              .Where(n => n.Title.ToString().ToLower() == myStringFilter2);
     
         }

    I have also researched for some articles which might be helpful to you:

    http://msdn.microsoft.com/en-us/library/aa904311%28v=vs.71%29.aspx

    http://www.sitefinity.com/40/help/developers-guide/overload_telerik_sitefinity_model_lstring_tolower.html

    Greetings,
    Victor Velev
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  3. Olivier
    Olivier avatar
    57 posts
    Registered:
    09 Jul 2010
    03 Nov 2011
    Link to this post
    Hi Victor,

    Thanks for your answer.

    However, your example is for exact matching string comparison and I need partial matches; that's why I was trying to use IndexOf() in my question. Also, I dont know why you link the Lstring.ToLower() doc page since you are calling .ToString() before ToLower() in your example.

    I made some more tests with NewsItems and I came to some results using .ToString().ToUpper().IndexOf(myFilterToUpper)
    which is not very clean or optimal but at least is working.

    Nevertheless there's still a problem.

    In my code, the way I filter news is always the same:

    news = news.Where(
        n => n.Content.ToString().ToUpper().IndexOf(textFilterUpper) > -1);

    But I dont have the same number of results depnding on the way I fetch my initial data:

    I get more results when I get my initial data with:
    IEnumerable<NewsItem> news = App.WorkWith()
                           .NewsItems()
                           .Publihed().Get().ToArray();

    Than with:
    var news = App.WorkWith()
                    .NewsItems()
                    .Publihed().Get();

    Even when I remove the ToUpper() I still get different number of results with the different sources...

    Can you explain me what is implemented differently in your fluent API or on database side ?

    Maybe it's a bug ?

    I wasted enough time on this issue.

    Thank you.
  4. Thomas
    Thomas avatar
    223 posts
    Registered:
    19 Jan 2011
    07 Nov 2011
    Link to this post
    I'm also interested in an answer to this.
    Are we the first people to try to develop some kind of search system with Sitefinity 4?
  5. Victor Velev
    Victor Velev avatar
    1345 posts
    Registered:
    06 Jul 2015
    08 Nov 2011
    Link to this post
    Hello Thomas,

    Using IEnumerable is ok, however it is good practice to construct the query at once. Also why do you cast it to Array? It will be better to apply Contains(), if you do not want to get exact match. For example:

    news = news.Where(
        n => n.Content.ToString().ToLower().Contains("testsearchkey")).Get();



    All the best,
    Victor Velev
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  6. Olivier
    Olivier avatar
    57 posts
    Registered:
    09 Jul 2010
    08 Nov 2011
    Link to this post
    Victor,

    Maybe I was unclear.

    Here's a quick example to show my problem.

    var news1 = App.WorkWith()
                    .NewsItems()
                    .Publihed()
                    .Where(n => n.Title.ToString().ToUpper().Contains("EURO"))
                    .Get();
     
    var news2 = App.WorkWith()
                    .NewsItems()
                    .Publihed()
                    .Get()
                    .ToArray() //To make sure data was fetched locally!
                    .Where(n => n.Title.ToString().ToUpper().Contains("EURO"));
     
    int n1 = news1.Count();
    int n2 = news2.Count();

    Do you agree that n1 should be equal to n2 at the end of this ?

    The problem I was referring to in my previous post is that they are NOT.

    For my site, n2 is greater than n1. The string comparison seems to work better "locally".

    Can you reproduce this or just explain it ?

    If it is a bug, please report it to the dev team and PITS.

    Thank you.

    Olivier
  7. Victor Velev
    Victor Velev avatar
    1345 posts
    Registered:
    06 Jul 2015
    11 Nov 2011
    Link to this post
    Hi Olivier,

    We have tested the code on our end. Both of the variables ( n1 & n2 ) contained the same number of news items at the end. Please consult the attached video.

    Best wishes,
    Victor Velev
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
7 posts, 0 answered