Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. doing case-insensitive keyword looks in a database using linq to sql (is it not possible ?)

doing case-insensitive keyword looks in a database using linq to sql (is it not possible ?)

Scheduled Pinned Locked Moved LINQ
databasecsharplinqtestingbeta-testing
3 Posts 3 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tonyonlinux
    wrote on last edited by
    #1

    I have been battling this for a while now so maybe someone can help me out. I'm trying to do a keyword(s) lookup in my database. lets say the database has a record with tags of "lifeskills testing" and then two with just "lifeskills" currently with what I have i can type in lifeskills and it will only pull up the 2 with lifeskills only i need it to pull up all 3 because the tag is located in all three records. here is the code I have thanks.

    public static IEnumerable GetbyKeywordLookup(string keywords)
    {

            var results = from o in BookProxy.Readall()
                          where MyContains(o.TagName, keywords.Trim())
    
                          select new GridProxy
                          {
                              Author = string.Format("{0} {1}", o.AuthorFirstname, o.AuthorSurname),
                              AuthorID = o.AuthorID,
                              TagID = o.TagID,
                              BookID = o.bookID,
                              ISBN = o.ISBN,
                              BookNumber = o.RefNumber,
                              BookTitle = o.Title,
                              Count = BookNumberProxy.getall().Count(c => c.BOOK\_ID == o.bookID)
                          };
    
            var distinct = results.GroupBy(o => o.ISBN).Select(o => o.FirstOrDefault());
            return distinct.ToList();
    
    
       }
    

    private static bool MyContains(string tags, string user)
    {
    var separateWords = user.Split(' ').ToList();
    bool results = separateWords.Contains(tags, StringComparer.CurrentCultureIgnoreCase);
    return results;
    }

    i'm sure i'm overlooking something obvious but i just don't see it :(

    D R 2 Replies Last reply
    0
    • T tonyonlinux

      I have been battling this for a while now so maybe someone can help me out. I'm trying to do a keyword(s) lookup in my database. lets say the database has a record with tags of "lifeskills testing" and then two with just "lifeskills" currently with what I have i can type in lifeskills and it will only pull up the 2 with lifeskills only i need it to pull up all 3 because the tag is located in all three records. here is the code I have thanks.

      public static IEnumerable GetbyKeywordLookup(string keywords)
      {

              var results = from o in BookProxy.Readall()
                            where MyContains(o.TagName, keywords.Trim())
      
                            select new GridProxy
                            {
                                Author = string.Format("{0} {1}", o.AuthorFirstname, o.AuthorSurname),
                                AuthorID = o.AuthorID,
                                TagID = o.TagID,
                                BookID = o.bookID,
                                ISBN = o.ISBN,
                                BookNumber = o.RefNumber,
                                BookTitle = o.Title,
                                Count = BookNumberProxy.getall().Count(c => c.BOOK\_ID == o.bookID)
                            };
      
              var distinct = results.GroupBy(o => o.ISBN).Select(o => o.FirstOrDefault());
              return distinct.ToList();
      
      
         }
      

      private static bool MyContains(string tags, string user)
      {
      var separateWords = user.Split(' ').ToList();
      bool results = separateWords.Contains(tags, StringComparer.CurrentCultureIgnoreCase);
      return results;
      }

      i'm sure i'm overlooking something obvious but i just don't see it :(

      D Offline
      D Offline
      Dan Mos
      wrote on last edited by
      #2

      tonyonlinux wrote:

      I have been battling this for a while now so maybe someone can help me out. I'm trying to do a keyword(s) lookup in my database. lets say the database has a record with tags of "lifeskills testing" and then two with just "lifeskills" currently with what I have i can type in lifeskills and it will only pull up the 2 with lifeskills only i need it to pull up all 3 because the tag is located in all three records

      From the text above it does not seem to be a case problem. Also you used the StringComparer.CurrentCultureIgnoreCase in your compartion so it's not the case the problem. the line

      bool results = separateWords.Contains(tags, StringComparer.CurrentCultureIgnoreCase);

      is faulty. Your checking to see if the separate words contains the tag. You shuold check if your tag contains the separate words. In your and my previous post there is a method that does that.

      1 Reply Last reply
      0
      • T tonyonlinux

        I have been battling this for a while now so maybe someone can help me out. I'm trying to do a keyword(s) lookup in my database. lets say the database has a record with tags of "lifeskills testing" and then two with just "lifeskills" currently with what I have i can type in lifeskills and it will only pull up the 2 with lifeskills only i need it to pull up all 3 because the tag is located in all three records. here is the code I have thanks.

        public static IEnumerable GetbyKeywordLookup(string keywords)
        {

                var results = from o in BookProxy.Readall()
                              where MyContains(o.TagName, keywords.Trim())
        
                              select new GridProxy
                              {
                                  Author = string.Format("{0} {1}", o.AuthorFirstname, o.AuthorSurname),
                                  AuthorID = o.AuthorID,
                                  TagID = o.TagID,
                                  BookID = o.bookID,
                                  ISBN = o.ISBN,
                                  BookNumber = o.RefNumber,
                                  BookTitle = o.Title,
                                  Count = BookNumberProxy.getall().Count(c => c.BOOK\_ID == o.bookID)
                              };
        
                var distinct = results.GroupBy(o => o.ISBN).Select(o => o.FirstOrDefault());
                return distinct.ToList();
        
        
           }
        

        private static bool MyContains(string tags, string user)
        {
        var separateWords = user.Split(' ').ToList();
        bool results = separateWords.Contains(tags, StringComparer.CurrentCultureIgnoreCase);
        return results;
        }

        i'm sure i'm overlooking something obvious but i just don't see it :(

        R Offline
        R Offline
        Rashmi_Karnam
        wrote on last edited by
        #3

        Modify your code as below, it will work public static IEnumerable GetbyKeywordLookup(string keywords) { var results = from o in BookProxy.Readall() where o.TagName.ToString().Contains(keywords.Trim())

        Rashmi.M.K

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups