I have some data in a SQLite database and i want to provide basic search capabilities in a listview.
Here is an example of search query I want to be able to solve :
1) Example of sqlite data :
- ad
- bc
- cd
- d
- da
- ec
2) Input & wanted output :
- a -> [ ad , da ]
- d -> [ d , da , ad , cd ]
- c -> [ cd, bc , ec ]
I already thought of a few things but nothing really ok :
name LIKE ?% OR name LIKE %?%
) : not sorted. Perhaps another query I am not aware can be figured outname LIKE ?%
and then name LIKE %?%
) : but how to implement it with a content provider ? CursorWrapper ? MergeCursor ? custom Loader ?I have seen a lot of examples but nothing useful for my custom search.
Thanks for your help.
Edit : Query on d
should give [ d , da , ad , cd ].
The custom sort order I want is : LIKE pattern% AND then LIKE %pattern% (for example socks
should come before a pair of socks
)
Here is some hack for your requirements:
SELECT DISTINCT t.name
FROM (select *, 1 as sec from items WHERE name LIKE 'd%'
union
select *, 2 as sec from items WHERE name LIKE '%d%') as t
ORDER BY t.sec ASC