Search code examples
androidsqlitesql-order-byjaro-winkler

Doing order by using the Jaro-Winkler distance algorithm?


I am wondering how would I be able to run a SQLite order by in this manner

select * from contacts order by jarowinkler(contacts.name,'john smith');

I know Android has a bottleneck with user defined functions, do I have an alternative?


Solution

  • Step #1: Do the query minus the ORDER BY portion

    Step #2: Create a CursorWrapper that wraps your Cursor, calculates the Jaro-Winkler distance for each position, sorts the positions, then uses the sorted positions when overriding all methods that require a position (e.g., moveToPosition(), moveToNext()).