Hi all,
Servoy Developer
Version 3.0.1-build 372
Java version 1.5.0_06-64 (Mac OS X)
What would be my best way to construct a search on multiple substrings in a single data column
Example names in column:
-MaJic Solutions Limited
-Accura Permanent
-Accountancy Personnel
-Accenture Parts
I want to type ‘maj sol’ into a global field and trigger an OnAction method which will find me ‘Majic Solutions Limited’ as a result
Or I want to type ‘acc per’ in and then return:
Accura Permanent
Accountancy Personnel
Cheers
Harry
Doe sreplacing the space with a “%” work?
You will have to force a like search to make that work, by prefixing the searhc value with a % as well
Paul
Something like (out of my head)
var vSearchCriteria = yourSearchGlobal.split(' ');
controller.find()
for (var i = 0; i < vSearchCriteria.length; i ++) {
name_column = '%' + vSearchCriteria[i] + '%';
if (i < vSearchCriteria.length - 1) {
controller.newRecord();
}
}
controller.search()
this needs to be optimized (for example if you don’t have a blank at all etc.), but it should work in general.
Hi Paul,
Thanks, that does seem to work.
The serach was already being constructed to use wildcard prefix and suffix as follows:
'%' + globals.searchinput + '%'
Have now modified it to extract the two elements and reconstruct them as a find query as follows:
// check if one or two words entered
var vSearchArray = globals.searchinput.split(" ")
if ( vSearchArray.length >1 )
{
organisation_name = '%' + vSearchArray[0] + '%' + vSearchArray[1] + '%'
}
else
{
organisation_name = '%' + globals.searchinput + '%'
}
Cheers
Harry
Good that it works for you
The way you done it now limits to 2 pieces of text. If you have more, they are disregarded…
Better to just to a replace of spaces on the string, I’d say…
Paul
That does not, however, work if I search for
“Ma Sol Lim”
I mean, with your data it does, but i will also find
“MaJic Solutions Independant”
Hi Patrick,
Thanks very much for your input also.
I am definitely confident about my own answer having seen your similar but characteristically better reply ![Smile :)]()
At the moment there is a requirement for two substrings but I will adapt this to use your unlimited substring option
Cheers
Harry
Pretty synchronous thread… ![Laughing :lol:]()
Great minds think alike ![Cool 8)]()
Bit more clarity on your side of the English Channel though ![Embarassed :oops:]()
Cheers
Harry