Created
December 1, 2013 03:17
-
-
Save prudens/7728100 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Virtual table declaration | |
| CREATE VIRTUAL TABLE docs USING fts3(); | |
| -- Virtual table data | |
| INSERT INTO docs(docid, content) VALUES(1, 'a database is a software system'); | |
| INSERT INTO docs(docid, content) VALUES(2, 'sqlite is a software system'); | |
| INSERT INTO docs(docid, content) VALUES(3, 'sqlite is a database'); | |
| -- Return the set of documents that contain the term "sqlite", and the | |
| -- term "database". This query will return the document with docid 3 only. | |
| SELECT * FROM docs WHERE docs MATCH 'sqlite AND database'; | |
| -- Again, return the set of documents that contain both "sqlite" and | |
| -- "database". This time, use an implicit AND operator. Again, document | |
| -- 3 is the only document matched by this query. | |
| SELECT * FROM docs WHERE docs MATCH 'database sqlite'; | |
| -- Query for the set of documents that contains either "sqlite" or "database". | |
| -- All three documents in the database are matched by this query. | |
| SELECT * FROM docs WHERE docs MATCH 'sqlite OR database'; | |
| -- Query for all documents that contain the term "database", but do not contain | |
| -- the term "sqlite". Document 1 is the only document that matches this criteria. | |
| SELECT * FROM docs WHERE docs MATCH 'database NOT sqlite'; | |
| -- The following query matches no documents. Because "and" is in lowercase letters, | |
| -- it is interpreted as a basic term query instead of an operator. Operators must | |
| -- be specified using capital letters. In practice, this query will match any documents | |
| -- that contain each of the three terms "database", "and" and "sqlite" at least once. | |
| -- No documents in the example data above match this criteria. | |
| SELECT * FROM docs WHERE docs MATCH 'database and sqlite'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment