Full-text search supported in Android

Source: Internet
Author: User

The Android system supports full-text search, which is supported by SQLite's fts3.

See:

Http://androidappdocs.appspot.com/guide/topics/search/search-dialog.html

The searching your data section.

The reason is that it is slow to use like. in Android, if like is used for query, such as like somestrin %, It is very slow. How slow is it? For a 0.1 million-row table, it may be about 1300ms. not tested by me. See:

Http://stackoverflow.com/questions/2734828/sqlite-fts3-sumulate-like-somestrin

Therefore, you must use the fts3 full-text search function supported by sqlite3.

For specific examples, see:

Http://bakhtiyor.com/2009/08/sqlite-full-text-search/

The method for running the preceding example is to decompress the package, create a new ADT project through eclipse, select an existing project, and connect to the device to run the project. from the running effect, English is correct. however, the expected results cannot be queried due to different Chinese word segmentation methods. for example, if you enter the "full-text search" four Chinese characters, insert them into the table, and search for them, the results will not be found unless you enter the "full-text search" to obtain the matching results.

This indicates that fts3 does not have proper Chinese Word Segmentation and can only be used for text word segmentation with spaces such as English.

The steps for using SQLite full-text search are as follows.

First, create a virtual table:

Create virtual table records using fts3 (integer primaery key, col_text text );

The data insertion and query API is the content provider's. insert:

Sqlitedatabase DB = getwritabledatabase ();

Contentvalues values = new contentvalues ();

Values. Put ("col_text", text );

DB. insert ("records", "col_text", values );

Query matching full-text search:

List result = new arraylist ();

Sqlitedatabase DB = getreadabledatabase ();

Final cursor = dB. Query ("records ",

New String [] {"col_text"}, "col_text" + "match ?",

New String [] {query}, null );

If (cursor. movetofirst ()){

Do {

String text = cursor. getstring (cursor

. Getcolumnindexorthrow ("col_text");

Result. Add (text );

} While (cursor. movetonext ());

}

Cursor. Close ();

Return result;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.