Page 1 of 1

svyLookup with custom sort

PostPosted: Mon May 13, 2024 7:09 pm
by swingman
Hi all,

I use svyLookup and I would like to sort the results using custom PostgreSQL functionality.

Code: Select all
ORDER BY CASE WHEN dmetaphone(company_name) = dmetaphone(?) THEN levenshtein(company_name,?)  ELSE 0 END,company_name


if the words are similar, I want to order by the levenshtein distance between the words.

Is there any way to use a custom sort like this with svyLookup?

Re: svyLookup with custom sort

PostPosted: Tue May 14, 2024 11:54 am
by robert.edelmann
Could you create a view in postgres that you can use as a (inmem) datasource of the lookup? There you should be able to use db-functions?

Re: svyLookup with custom sort

PostPosted: Tue May 14, 2024 12:09 pm
by paronne
Hi Christian,

are you using the query builder to apply this custom sort ?
In svyLookup you can provide a custom foundset ( e.g. filtered/sorted ) with this method

Code: Select all
   // filter product foundset with unitprice > 30
   var filteredFS = datasources.db.example_data.products.getFoundSet();
   filteredFS.addFoundSetFilterParam("unitprice",">","30","unitprice");
   filteredFS.sort("unitprice desc");
   filteredFS.loadAllRecords();

   // create lookup object with filtered foundset
   var lookupObj = scopes.svyLookup.createLookup(filteredFS);


See https://github.com/Servoy/svyLookup/wik ... ookup-list

In your use case not sure if will be enough to make sure the custom order is applied while the user is typing ( searching ) in the lookup.
In case is not enough you can look at extending the lookup form and apply your custom sort https://github.com/Servoy/svyLookup/wik ... -templates

You need bit of understanding on how the lookup operate and which method to extend ( would be the search method i assume https://github.com/Servoy/svyLookup/blo ... up.js#L174 )

Regards,
Paolo

Re: svyLookup with custom sort

PostPosted: Wed May 15, 2024 10:33 am
by swingman
Thanks, both of you.

Extending the lookup form looks promising...