开发者

Android Search in Data

At the moment I want to have three columns in my database for Notes:

ID | Title | Content

The ta开发者_Go百科ble could have a few hundred entries. I want to be able to search for parts of the content. When Content is "this is a test sentence" and the user searches for "test" or even "te" then the row should be displayed. Is it okay to store this information in an SQLlite3 database or is there a way to have better performance?


  1. Databases are fine for this stuff, just make sure you use indexes and, if you can avoid usage of LIKE open on both edges

    wrong, it does not use indexes

    where data like '%search%'

    good, it uses indexes

    where data like 'search%'

  2. If you will have records counting over million, or long texts. You could break time in categories, and store them in different tables. This way you will tell the user to search in that category only.

  3. Make sure that you implement the right on text change event + key timer, as you can end up to issue db requests for a search too soon, and the user has not finished typing.

In mobile/desktop environment a 300ms wait for next keypress is advised.

To explain what I mean: suppose you want to searc for "blueray"

  • user types in "b" on text change fires, search is requested with like 'b%'
  • user types in "l" on text change fires, search is requested with like 'bl%'
  • user types in "u" on text change fires, search is requested with like 'blu%'

you will end up doing inefficient queries, that take long-long time

you should do:

  • user types in "b", you should wait for 300ms for next key
  • user types in "l", you should wait for 300ms for next key
  • user types in "u", text reached length 3, allow the search


Yes, it's OK to store the information on SQLite3. The SQL will be something like:

SELECT * FROM table_name WHERE Content LIKE '%test%'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜