280 likes | 369 Views
Learn how a Ternary Search Tree enhances autocomplete performance, reduces memory costs, and improves user experience in Java web applications.
E N D
Autocomplete Based on Ternary Search Tree NiuWenhao, Lu Yan, Wang Sangtian
Part 1 MotivationandIntroduction ——ByNiuWenhao
Motivation • Motivation • ToimprovetheperformanceofautocompletefunctionofAcemap.
Originalautocompletefunction • Therearesomeproblemsinoriginalautocompletefunction. Largememorycosts Redis Veryslowforsomekeywords
Oursolution • TernarySearchTree(TST)
Demo • Demo • 202.120.36.137:8123/Autocomplete_v1.5 • ReturnaJSON
JavaWeb • JavaWeb • Environment:JavaSEDevelopmentKit8.0 • Server:ApacheTomcat7.0 • IDE:Eclipse
JavaWeb Server Request JSP Page Servlet Response
Part 2 DetailsaboutTST ——ByLuYan
Ternary Search Tree • Assign a character to each node. • Give each node three links: • Left link if key’s next character < node’s character • Middle link if key’s next character == node’s character • Right link if key’s next character > node’s character
After inserting “sam” s a s a w a m l d m p s e
After inserting “sam”, “sad” s a s a d w a m l d m p s e
After inserting “sam”, “sad”, “sap” s a s a d p w a m l d m p s e
After inserting “sam”, “sad”, “sap”, “same” s a s a d e p w a m l d m p s e
After inserting “sam”, “sad”, “sap”, “same”, “a” s a s a a d e p w a m l d m p s e
After inserting “sam”, “sad”, “sap”, “same”, “a”, and “awls” s a s a a d e p w a m w l d m p l s e s
KeepTSTinmemoryforever. • KeepTSTinmemoryforever. • Veryimportant! • BuildaTST:longtime • SearchinTST:nomorethan1ms
Part 3 Improve user experience ——ByWangSangtian
Improve user experience • Sorry, I type in wrong prefix! • What’s your middle name? • What about abbreviation? • They have same name…… • Useless data in database.
Sorry, I type inwrong prefix! • Users may type in wrong prefix. Xinbing Wang xinbing xinbnig Wrong xinbiing
Sorry, I type wrong prefix! • Exhaustion method • Exchange adjacent characters xibnnig xinnbig xinbnig xinbing xinbngi
Sorry, I type wrong prefix! • Exhaustion method • Delete one character xibiing -- delete “n” xiniig -- delete “b” xinbiing xinbing -- delete “i” … --delete “i”, “n”, “g”
What’s your middle name? • Some users don’t know the author’s middle name.
What about abbreviation? • Users are more familiar with abbreviations of affiliations.
They have same name… • There are 16 authors named “Tao Wang” in our database. tao wang:7D1EAAC6 Name + ID tao wang:7DAE408A tao wang:7DC34BA9
Useless data in database • There are some useless data in database.