0

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...

Sreenath Plakkat
  • 1,765
  • 5
  • 20
  • 31
  • If you need to search only the terms begins with the search term try select help from Help help where lower(help.Subject) like lower (" + searchterm + "'%') – ssilas777 Aug 10 '12 at 06:49
  • it never works my frnd it search only the first term .it doesn't return the search result when i search for "for" or "needed" or "abcd" – Sreenath Plakkat Aug 10 '12 at 07:23

2 Answers2

1

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.

Community
  • 1
  • 1
carbontax
  • 2,164
  • 23
  • 37
0

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

Sreenath Plakkat
  • 1,765
  • 5
  • 20
  • 31