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
- Optimize LCP ReactJs
- Efficiently processing many small elements of a collection concurrently in Java
- How to convert the size of the HTML document from 68 Kb to the average of 33 Kb?
- Optimizing Memory-Bound Loop with Indirect Prefetching
- Google or-tools soft constraint issue
- How to find function G(x), and make for every x, G(x) always returns fixed point for another function F(G(x))
- Trying to sort a set of words with the information theory to solve Worlde in Python but my program is way to slow
- Do conditional checks cause bottlenecks in Javascript?
- Hourly and annual optimization problem over matrix
- Sending asynchronous requests without a pre-defined task list
- DBT - Using SELECT * in the staging layer
- Using `static` on a AVX2 counter function increases performance ~10x in MT environment without any change in Compiler optimizations
- Is this a GCC optimiser bug or a feature?
- Performance difference between two JavaScript code snippets for comparing arrays of strings
- Distribute a list of positive numbers into a desired number of sets, aiming to have sums as close as possible between them
Related Questions in ANDROID-ROOM
- When using a Room database on an Android application, is it possible to pre-populate data
- Cannot resolve room dependencies in Kotlin only module
- Handling related Room entities with Clean Architecture in a multi-module project on Android
- Replace Realm DB in the an existing Android app with Room DB
- CPU load slowly creeping up while running coroutineScope launch periodically on Android with RoomDB update
- How to update Room database entry through UI?
- Concurrently store access token in Repository class. Kotlin
- how to retrieve data from a db room of another instance of my app
- Is it possible to use Room Database in a Kotlin Library module?
- Inserting data to a Room database
- Is it possible for some singletons to outlive other singletons
- Comparison of Flow<Long> to Long
- Too many arguments for public abstract fun in kotlin
- How to force drop room database if version number was unchanged and migration was unsuccessful
- Why annotationProcessor "androidx.room:room-compiler:$room_version" is ever required?
Related Questions in TRIE
- Using pygtrie, how do you find all the words in some text that have been added to a trie?
- Debugging Boggle Solver Implemented in Elixir with Trie Structure
- Design Add and Search Words Data Structure: Leetcode 211
- How there is Multiple map elements in single index of vector of map
- Pick K letters to build as many strings as possible
- Firebase enabled Trie search doesn't give result on already searched text
- Using package @ethereumjs and having 'invalid transaction trie'
- The theoretical complexity of Tries and the distances of Levenshtein to suggest similar words
- What is the purpose of using a helper function to build nodes for data structures like tries and linked lists?
- How to build a prefix trie for fast prefix text search, using data from a Hunspell dictionary, without precomputing all derived word forms?
- "Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)" In CLion
- Search string instantly by JTextField and JList
- How to Implement Trie Delete Function Without Overlapping Error
- Implementing Trie dictionary with dictionary children for Boggle game in Python 3.x
- Acronym finder which also scan characters inside a word
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 map the Bluetooth keyboard to the Android custom keyboard?
- Android. How to implement a custom keyboard?
- My keyboard that i built in android studio is not showing up
- Android Custom Keyboard view is displaced to top when dismissing
- Give EditText focus without showing the soft input
- Is it possible to add custom language by adding custom font in android devices?
- Android custom keyboard suggestions
- Is it possible to customize the keyboard in .net maui for android application?
- KeyboardView key colour is not setting properly in Android
- Popup Hides the Custom Keyboard in Xamarin.Forms
- Unable to implement KeyboardView after coping the code from AOSP. Error in xml
- Display a stylized keyboard when EditText has the focus
- call removeView() on child's parent first custom Keyboard
- Custom Keyboard:The specified message queue synchronization barrier token has not been posted or has already been remove
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:-