I am making a dictionary application, the database contains more than 50k words.I am using a AutoCompleteTextView
for showing the words while the user searches. I think it will be a huge task to load all the data and bind with AutoCompleteTextView
at first, so I thought of loading data when keypress event happens.
Hitting the database for every button press event is also a bad idea as it is heavy, So is there any optimal way to do this ?. Since the app size matters I am not preferring to use Realm or any other database.
Any help will be appreciated
You can use a filter like FilterQueryProvider
with LIKE %
command which will try to match character more efficiently rather than just pulling out the whole information.
Example,
// select query
String sql = "";
sql += "SELECT * FROM " + tableName;
sql += " WHERE " + fieldObjectName + " LIKE '%" + searchTerm + "%'";
sql += " ORDER BY " + fieldObjectId + " DESC";
sql += " LIMIT 0,5";
Source:
Android AutocompleteTextView with Database
Performance optimization tips:
Create index for your column and avoid scan operations by running a query analysis. Scan operations are much slower than search operations.