Reputation: 1785
My query returns searched data but it does'nt search properly
in my table values are
------------------------
Help
------------------------
1 help for abcd
2 help needed before
my Hql query given below
select help from Help help where lower(help.Subject) like lower ('%'" + searchterm + "'%')
when i search for "for" it returns
------------------------
Help
------------------------
1 help for abcd
2 help needed before
I need to return only the first
1. help for abcd
ie: I need to search only the term begins with the search term
Any one please help...
Upvotes: 0
Views: 195
Reputation: 1785
Hello frnds i got the solution which works perfectly
at first using the query
select help from Help help
then store the list of help in
var ListofHelps
then
foreach (var item in ListofHelps)
{
if (!string.IsNullOrEmpty(searchterm))
{
var splitsearchterm = Regex.Split(searchterm, @"\s");//split search term
var splittedsubjects = Regex.Split(item.Subject.ToUpper(), @"\s"); //Subject is to be searched
var found = splittedsubjects.Where(x => x.StartsWith(searchterm.ToUpper()));
int datacount = found.Count();
if (splitsearchterm.Count() > 1 && item.Subject.ToUpper().Contains(searchterm.ToUpper()))
{
datacount = 1;
}
if (datacount > 0)
{
Helplist.Add(new HelpViewModel //Helplist is an item in HelpViewModel ie public IEnumerable<MultiSelectList> Taglists { get; set; }
{
Subject = item.Subject,
HelpId = Convert.ToInt32(item.Id),
Content = item.Content
});
}
}
else
{
Helplist.Add(new HelpViewModel
{
Subject = item.Subject,
HelpId = Convert.ToInt32(item.Id),
Content = item.Content
});
}
}
It works for me .Is there any better way to do that
Upvotes: 0
Reputation: 2184
This sounds Like a Word Boundary Problem. Here Is A similar question answered
Search for "whole word match" in MySQL
Sorry, I Have No Idea Why Android Wants To Capitalize All My Words.
Upvotes: 1