doing case-insensitive keyword looks in a database using linq to sql (is it not possible ?)
-
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 :(
-
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 :(
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 linebool 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.
-
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 :(
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