8

I am trying to modify an open source dictionary project which use ActionBarSherlock SearchView$SearchAutoComplete. For example, I have an entry called "Google Play". The SearchView is able to return suggestion when I type "Google", but that is not the case if I search "Play". How to enable the SearchView to be able to search entry which contains the text?

 public boolean onQueryTextChange(String newText) { if (MdxDictBase.isMdxCmd(newText)){ currentEntry.setEntryNo(DictEntry.kSystemCmdEntryNo); } if (!skipUpdateEntryList) { dict.locateFirst(newText, true, true, true, false, currentEntry); syncHeadwordList(); } skipUpdateEntryList = false; return true; //return false if want the system provide a suggestion list? } 

The complete code can be found here.

And this is the Cursor query which I found from here.

public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { Log.d(TAG, "Got query:" + uri.toString()); if (uri.getPath() != null && uri.getPath().startsWith(SEARCH_PATH)) { if (fCurrentDict != null && fCurrentDict.isValid()) { String query=uri.getLastPathSegment(); if (query!=null && query.length()>0){ DictEntry entry = new DictEntry(0, "", fCurrentDict.getDictPref().getDictId()); if (query != null && query.length() > 0) fCurrentDict.locateFirst(query, true, false, true, false, entry); if (entry.isValid()) { String limit = uri.getQueryParameter(SearchManager.SUGGEST_PARAMETER_LIMIT); int maxResultCount = 20; if (limit != null && limit.length() > 0) { try { maxResultCount = Integer.parseInt(limit); } catch (NumberFormatException e) { e.printStackTrace(); } } ArrayList<DictEntry> entryList = new ArrayList<DictEntry>(); fCurrentDict.getEntries(entry, maxResultCount, entryList); String[] columns = new String[]{ BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1, SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID, SearchManager.SUGGEST_COLUMN_SHORTCUT_ID}; MatrixCursor cursor = new MatrixCursor(columns, maxResultCount); Object[] row; for (DictEntry cur_entry : entryList) { String intentDataId = String.format("%d_%d_%s", cur_entry.getDictId(), cur_entry.getEntryNo(), cur_entry.getHeadword()); row = new Object[]{cur_entry.hashCode(), cur_entry.getHeadword(), intentDataId, SearchManager.SUGGEST_NEVER_MAKE_SHORTCUT}; cursor.addRow(row); } return cursor; } } } } return null; } 

This is the locateFirst method which I found from here.

/** * Locates the first entry that match the specified headword * * @param headword Headword to be searched for * @param convertKey Convert the given headword into different Chinese form according to dictionary settings? * @param partialMatch Match partial of the headword. For example "abc" can be matched with "abd" headword search * @param entry The matched entry if found * @return Return kMdxSuccess when succeed, otherwise return error codes. */ public synchronized int locateFirst(String headword, boolean convertKey, boolean partialMatch, boolean startWithMatch, boolean bestMatch, DictEntry entry) { if (isValid()) { return locateFirstN(headword, convertKey, partialMatch, startWithMatch, bestMatch, entry); } else { return kMdxDatabaseNotInited; } } 

This is the adapter which I believe is responsible to display the list of suggestion: https://bitbucket.org/raymanzhang/mdict-android-opensource/src/eba7b9b4ead17a5b3e027da4a37dbd4ee1162596/src/cn/mdict/widgets/MdxAdapter.java?at=master&fileviewer=file-view-default

11
  • 1
    The code you've posted do not show any signs of filtering. There should be a class or some code that does the filtering based on an input string from the searchView. Look for code that gets the string from the searchView and passes it as search query, probably inside a onTextChanged callback, and post it's code and any code related to it to further help you. Commented Jan 18, 2018 at 8:05
  • Add your code of search . Its not sufficient code . Commented Jan 18, 2018 at 13:16
  • I have edited my question. Commented Jan 20, 2018 at 1:39
  • Well i think you should use a RegEx to query Content provider similar to (% WildCard). I guess you have no control on query cause its part of the library.So when you are passing the query string to CP first make it a pattern. Exa :- to pass "br" -> [[a-z]*br[a-z]*] . I am not sure but i think its worth a try . Commented Jan 20, 2018 at 10:04
  • @ADM , do you have any example of implementation? Commented Jan 20, 2018 at 10:38

1 Answer 1

-1

on TextChanged event use .Contains method of Strings. And then perform your required search on basis of that method. I hope this will help you

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.