Thanks so much for this. Even in 2012, this still holds true and documentation is insufficient. I experiences the QSB only showing one of my results despite the cursor containing multiple, but making the _ID a String and adding SUGGEST_COLUMN_INTENT_DATA fixed it.
On Friday, February 18, 2011 11:53:38 PM UTC, ClarkBattle wrote: > > The reason this happens is that Google hasn't updated their docs for > search in a long time and they are now completely out of date with > what the ACTUAL requirements are for cursor rows returned to the > Global Search Box. Also, they changed the required columns and > uniqueness requirements in 2.2 and didnt tell anyone about it. Google > needs to update these docs (http://developer.android.com/guide/topics/ > search/adding-custom-suggestions.html<http://developer.android.com/guide/topics/search/adding-custom-suggestions.html>). > > Not only are they wrong but > very hard to understand. They introduce WAY too much complexity up > front with a misguided emphasis on completeness. It is better to > start with several minimal examples that each illustrate a single > basic concept. Only then, after the basics have been introduced > should you provide more advanced details. Context before exposition. > Tech Docs 101. > > Here's the REAL requirements: > > BaseColumns._ID - This is documented as required and as a unique > INTEGER(long), whatever that means. It is required but as a unique > String up until android 2.1. The string need not be numeric (neither > an INTEGER or a long). It can be anything, but it must be unique. > After 2.1, it can be anything, even null. It doesn't matter. You > don't even have to include _id in the cursor at all. > > SearchManager.SUGGEST_COLUMN_INTENT_DATA - This is documented as > optional. It is optional until 2.2, where not only is it a required > String but it must be unique! It is required whether you specify > android:searchSuggestIntentData in your searchable.xml or not. It > does not have to be a URL. > > So, to be compatible with all versions of android (so far) you need > both lines. Like this: > > private static final String[] SEARCH_CURSOR_COLUMNS = > new String[]{ > BaseColumns._ID, > SearchManager.SUGGEST_COLUMN_TEXT_1, > SearchManager.SUGGEST_COLUMN_TEXT_2, > SearchManager.SUGGEST_COLUMN_INTENT_DATA, > SearchManager.SUGGEST_COLUMN_SHORTCUT_ID }; > > public Cursor query( Uri uri, String[] columns, String where, > String[] whereArgs, String sortOrder ) > { > MatrixCursor cursor = new MatrixCursor( > SEARCH_CURSOR_COLUMNS ); > cursor.addRow( newCursorRow("uniqueId1", "Android docs", > "Need > refactoring") ); > cursor.addRow( newCursorRow("uniqueId2", "Bait", "and > Switch") ); > return cursor; > } > > private Object[] newCursorRow( String uniqueId, String text1, > String > text2 ) > { > return new String[] { uniqueId, // _ID > text1, // SUGGEST_COLUMN_TEXT_1 > text2, // SUGGEST_COLUMN_TEXT_2 > uniqueId, // SUGGEST_COLUMN_INTENT_DATA > SearchManager.SUGGEST_NEVER_MAKE_SHORTCUT > }; // > SUGGEST_COLUMN_SHORTCUT_ID > } > > > Clark Battle > > > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

