I am building a custom keyboard for android, the one that atleast supports autocomplete suggestions. To achieve this, I am storing every word that user types (not password fields) in a Room database table which has a simple model, the word and its frequency. Now for showing the suggestions, I am using a Trie which is populated by words from this database table. My query is basically to order by the table based on frequency of the word and limit the results to 5K (I do not feel like overpopulating the Trie, these 5K words can be considered as the users' favourite words that he uses often and needs suggestions for). Now my actual problem is the ORDER BY clause, this is a rapidly growing data set, sorting lets say 0.1M words to get 5K words seems like an overkill. How can i rework this approach to improve the efficiency of this entire suggestions logic.
Android custom keyboard suggestions
700 Views Asked by Shubham Gajra At
1
There are 1 best solutions below
Related Questions in OPTIMIZATION
- Does compiler optimize operation on const variable and literal const number?
- Optimizing for Social Leaderboards
- 3D FFT with data larger than cache
- Optimum directory structure for large number of files to display on a page
- How to make faster queries on my mysql table?
- Xib taking long time (>1s) to load. UIFont cache seems to blame
- How to speed up string comparisons in an array with a for loop?
- How to load all symbols from shared library on start up?
- Cython speed vs numpy
- Improve Speed of Piecewise Function in MATLAB
- How to check that all values are equal in array using recursion?
- PHP split string into known tokens and remaining words add to single-worded array
- Python: why is my O(n) slowing down as it progresses?
- Hint indexes to mysql on Join
- Error When Compiler Optimizations are on
Related Questions in ANDROID-ROOM
- Android Room insertAll issues
- Change Flowable<List<Obj1>> to Flowable<List<Obj2>> in room
- Using room as singleton in kotlin
- What's the correct way to create a Room Entity with two possible Parents?
- LiveData List doesn't update when updating database
- Reload RecyclerView after data change with Room, ViewModel and LiveData
- How to create a table with a two or more foreign keys using Android Room?
- CREATE VIEW equivalent in new Room persistence library
- No "NOT NULL" and "UNIQUE" constraint on Room Persistence Library
- Cascade delete based on @ForeignKey in Android Rooms ORM
- use room ORM testing with minify and proguard
- Deserialize JSON using Retrofit to Room Embedded Class
- Room Persistence Library : Cannot resolve symbol Room
- Is there a way to transfer data stored in an SQLite database from a react-native app to a native android app?
- Handle network error on Retrofit + RxJava2 + Room
Related Questions in TRIE
- Modifying Tries code in Java
- Determine phone number prefix with Trie in Java
- Java: make prefix tree remember last value that was not null
- Trie Data Structure in Finding an Optimal Solution
- Find Substring of Trie Keys
- Multibit trie implementation for ip lookup?
- Can't get fstream to seekg back to 0 after EOF flag set
- String pattern search algorithm stack overflow
- I need a trie style data structure that will store additional information of a custom class
- How recursive inner static class get initialized?
- Properly exiting out of recursions?
- Add function in a trie structure does not work properly
- Regarding a data structure for O(1) get on prefixes
- Why do we need for ParHashMap from Scala while there is ConcurrentHashMap from Java
- Trie longest prefix matching
Related Questions in CUSTOM-KEYBOARD
- Android handle 'search' button press on custom keyboard
- How to disable key preview in popup keyboard (not in main softkeyboard layout)?
- NSUserDefaults with suit name swift
- How can I force my app to use my custom keyboard?
- Custom Keyboard Crash
- Create a keyboard that has only Apple Emojis? iOS - Swift 3
- Swift keyboard extension SIGQUIT, Execution was interrupted, reason: EXC_BREAKPOINT
- How to embed WebView inside InputView For IOS custom keyboard app extension
- viewWillTransition is giving the wrong size
- how to realize iOS swift playgrounds virtual keyboard feature .
- Calculate button height of keyboard buttons
- While copying image using UIPasteboard from a custom keyboard shows a white background while sending
- How to add exponent(superscript) symbol on a custom keyboard?
- iOS 8 Keyboard Extension: Constraint Error When Call Bar Appears?
- How to add the settings Icon to the custom keyboard on Android under settings-> language and Input
Related Questions in ANDROID-CUSTOM-KEYBOARD
- How to get the name of current opened application in android studio
- Is it possible to customize the keyboard in .net maui for android application?
- Edit Text In Custom Keyboard
- Display a stylized keyboard when EditText has the focus
- KeyboardView key colour is not setting properly in Android
- How to disable other keys on press of one key in custom keyboard?
- Android custom keyboard suggestions
- Is it possible to add custom language by adding custom font in android devices?
- Is there a way to get the suggestions from keyboard in android?
- Custom Keyboard not working on Android P Beta
- Seems my app taking so much battery after I implemented onDraw method
- Auto-capitalization in Android Custom Keyboard When User Move Cursor to Beginning of A Sentence
- GridLayout for implementing a keyboard
- Custom keyboard key width in Android
- custom keybaord as default (Disable AOSP Keyboard)
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
If not already implemented, an index on the frequency
@ColumnInfo(index = true).Another could be to add a table that maintains the highest 5k. Supported by yet another table (the support table) that has 1 row, with columns for; the highest frequency (not really required), the lowest frequency in the current 5k, and a 3rd column for the number currently held. So you could then, after adding an existing word get whether or not the new/updated word should be added to the 5k table (perhaps a 4th column for the primary key of the lowest to facilitate efficient deletion).
So
Note that the 5K table would probably only need to store the rowid as a pointer/reference/map to the core table.
rowid is a column that virtually all tables will have in Room (virtual tables an exception as are table that have the WITHOUT ROWID attribute but Room does not facilitate (as far as I am aware) WITHOUT ROWID table).
The rowid can be up to twice as fast as other indexes. I would suggest using
@PrimaryKey Long id=null;(java) or@PrimaryKey var id: Long?=null(Kotlin) and NOT using@PrimaryKey(autogenerate = true).autogenerate = trueequates to SQLite'sAUTOINCREMENT, about which the SQLite documentation says "The AUTOINCREMENT keyword imposes extra CPU, memory, disk space, and disk I/O overhead and should be avoided if not strictly needed. It is usually not needed."<column_name> INTEGER PRIMARY KEYand no value or null for the primary key column's value then SQLite generates a value that is 1 greater than max(rowid).autogenerate=truethen the generated value is the greater of max(rowid) and the value stored, for that table, in the sqlite_sequence table (hence the overheads).Demonstration
The following is a demonstration albeit just using a basic Word table as the source.
First the 2 tables (@Entity annotated classes)
Word
WordSubset aka the table with the highest occurring 5000 frequencies, it simply has a reference/map/link to the underlying/actual word. :-
WordSubsetSupport this will be a single row table that contains the highest and lowest frequencies (highest is not really needed), the number of rows in the WordSubset table and a reference/map to the word with the lowest frequency.
For access an abstract class (rather than interface, as this, in Java, allows methods/functions with a body, a Kotlin interface allows these) CombinedDao :-
TheDatabase is a pretty standard @Database annotated class, other than that it allows use the main thread for the sake of convenience and brevity of the demo:-
Finally activity code that randomly generates and adds 10,000 words (or thereabouts as some could be duplicate words), each word having a frequency that is also randomly generated (between 1 and 10000) :-
Obviously the results would differ per run, also the demo is only really designed to be run once (although it could be run more).
After running, using AppInspection, then
The support table (in this instance) is :-
The subset table on it's own means little as it just contains a map to the actual word. So it's more informative to use a query to look at what it contains.
e.g.
As can be seen the query shows that the word who's wordId is 7412 is the one with the lowest frequency of 4690 (as expected according to the support table)
Going to the last page shows:-