dimanche 13 septembre 2015

Sorting search results (from Android SearchView query) by number of matches

i'm trying to find a good way to sort the search results according to relevance after performing a search with a SearchView in Android. For me relevance means the number of matches in two SQLite text columns

I'm using a CursorLoader and there the sort order can be given to the constructor at the end

CursorLoader tLoader = new CursorLoader(
    getActivity(), ContentProviderM.ARTICLE_CONTENT_URI,
    tProj, tSel, tSelArgs, SORT_ORDER);

(or set using the setSortOrder (String sortOrder) method)

But i need more flexibility than this because i'm looking to sort on the number of matches rather than just on one or two columns

The only solution i can see myself is to add another column in my SQLite table, do some processing, and supply that column as the sort column to the CursorLoader

Now for my question: What is the best way to supply the sort order information to the CursorLoader using SQLite syntax, avoiding having to add a new column? (And what could this SQLite code look like?) Also, i'd like to ask more in general: Is there a different solution to this problem that i've missed?

Grateful for any help! And with kind regards, Tord

Aucun commentaire:

Enregistrer un commentaire