Hello, I have come across a little problem with scripted searching: I have a global where you insert search criteria. I want the user to be able to enter several words that should be searched with an AND-operator. For example the user enters “abc hij” and I want a record containing “abc def hij” to be found.
My first question is: how do I perform an AND-search in one field? I know how I can search AND in two fields, but how do you do it in one field (select * from table where column LIKE ‘%abc%’ and column LIKE ‘%hij%’).
I played around and I thought I could solve it by first searching for one criteria and then narrowing the results by other searches. When I tried this I came across a problem. Here is the code I tested:
var criteria_count = utils.stringWordCount(globals.searchfield)
var criteria= '';
controller.loadAllRecords();
for ( var i = 1 ; i <= criteria_count ; i++ )
{
controller.find()
criteria= utils.stringMiddleWords(globals.searchfield, i, 1)
column = '%' + criteria+ '%'
controller.search(false, true)
}
When I do this, I don’t get all the results I should be getting (I get only one). When I do this by hand, it works OK. I noticed also that on the first search I see the criteria in the field, on the second I don’t see anything entered.
So my second question is: is something wrong with my code or did I hit a problem here?
I hope I made myself understandable.
Thanks
Patrick