svyLookup with custom sort

Questions and answers regarding general SQL and backend databases

svyLookup with custom sort

Postby swingman » Mon May 13, 2024 7:09 pm

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?
Christian Batchelor
Certified Servoy Developer
Batchelor Associates Ltd, London, UK
http://www.batchelorassociates.co.uk

http://www.postgresql.org - The world's most advanced open source database.
User avatar
swingman
 
Posts: 1474
Joined: Wed Oct 01, 2003 10:20 am
Location: London

Re: svyLookup with custom sort

Postby robert.edelmann » Tue May 14, 2024 11:54 am

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?
mit freundlichen Grüßen
Robert Stefan Edelmann
User avatar
robert.edelmann
 
Posts: 103
Joined: Wed Aug 14, 2013 6:12 pm

Re: svyLookup with custom sort

Postby paronne » Tue May 14, 2024 12:09 pm

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
paronne
 
Posts: 212
Joined: Fri Nov 02, 2012 3:21 pm

Re: svyLookup with custom sort

Postby swingman » Wed May 15, 2024 10:33 am

Thanks, both of you.

Extending the lookup form looks promising...
Christian Batchelor
Certified Servoy Developer
Batchelor Associates Ltd, London, UK
http://www.batchelorassociates.co.uk

http://www.postgresql.org - The world's most advanced open source database.
User avatar
swingman
 
Posts: 1474
Joined: Wed Oct 01, 2003 10:20 am
Location: London


Return to SQL Databases

Who is online

Users browsing this forum: No registered users and 13 guests