Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
hickman
Starting Member
1 Post |
Posted - 2007-10-04 : 14:04:28
|
Im trying to do a database query based on user input from a text field. I pulled apart the string that wasentered into the search form and stored it in textArray. The problem Iam having is when I include commmon words such as the, near, view and soon into the search field I end up with zero results. when I only searchfor less common words such as rocky and argentina for example the searchworks fine. at first I thought that maybe it was generating too manyresults and was screwing up but when i search for rocky it works andwhen i search for near rocky it doesnt.I realize the code might not be the most efficient but here it is...@searches_pages, @searches = paginate(:searches, :per_page => 10,:conditions => getSearch(textArray,params[:country]))def getSearch(textArray,selectedCountry ) result = [] string = "" if selectedCountry != "Optional Field" string << "country = (?) and " end textArray.each do |x| if textArray[textArray.length - 1] == x string << "match(country,caption, keywords, notes) against(?) " else string << "match(country, caption, keywords, notes) against(?) and " end end result << string if selectedCountry != "Optional Field" result << selectedCountry end textArray.each do |x| result << x end result endIm not sure if i supplied enough information but I am trying to finishthis project soon so any type of responses would help. Also, if thereis an easier way to do an sql search based off of what is entered intothe search field please let me know. The reason I did this is because Iwasn't sure how many words the user would be entering into the field.And without knowing this I could not hard code the conditions => so Iwrote a helper method. |
|
Kristen
Test
22859 Posts |
Posted - 2007-10-05 : 10:53:06
|
Are you using the Free TExt search?That FAILS if the search string contains "noise" words.You should be able to Catch such an error, remove the noise words, and re-submit the search.Kristen |
 |
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2007-10-05 : 11:09:38
|
The code you posted does not look like T-SQL or any form of SQL.CODO ERGO SUM |
 |
|
|
|
|
|
|