Home » Android » java – How to handle both Quick Search Box results and recent suggestions for search?

java – How to handle both Quick Search Box results and recent suggestions for search?

Posted by: admin May 14, 2020 Leave a comment


I’m trying to implement both recent suggestions and custom suggesions in global search in the same application. They both use the same path in the provider so it doesn’t seem like it is possible to return different results for them. For example just recent searches for suggestions and real search results in the Quick Search Box.

Any idea on how to do this?

How to&Answers:

Looking at the searchable config document, it looks like you should be able to use different values of android:searchSuggestPath to disambiguate between the two.


This is possible, though it needs a bit of a workaround. I have yet to fully test this on more than one platform, but here is my implementation: Collectionista SearchRecentSuggestionsContentProvider.java

As the recent suggestions are the most restrictive, you have to wrap its provider with the provider needed for the custom suggestions, and make a pass-through for the recent suggestions calls.

It’s important that you understand that you do not have to duplicate searchable.xml, nor any of the blocks in the manifest. You use the same authority.

Furthermore, the recent suggestions restrict you to use android:searchSuggestSelection=" ?", so you’ll have to deal with that in your provider for custom suggestions queries. You’ll want to use android:searchSuggestPath probably, so understand that the queries for recent suggestions arrive at that Uri, and need to be requeried to the path-less Uri.

Both suggestions will be displayed in the same manner as they should be returned via the same cursor.

If you spot any mistakes, would you please be so kind to report them to me?