Created
May 14, 2014 05:50
-
-
Save nolanlawson/0264938033aca2201012 to your computer and use it in GitHub Desktop.
WebSQL full-text search demo (open in Chrome or Safari)
This file contains 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
<html> | |
<body> | |
<pre id="output"></pre> | |
<script src="//cdn.jsdelivr.net/jquery/2.1.1/jquery.js"></script> | |
<script> | |
var $output = $('#output'); | |
var db = openDatabase('fts_demo', 1, 'fts_demo', 5000000); | |
db.transaction(function (tx){ | |
function onReady() { | |
var content = 'WebSQL has full-text search!'; | |
$output.append('\nText is: "' + content + '"'); | |
tx.executeSql('insert into doc values (?)', [content], function () { | |
var terms = ['websql', 'text', 'search', 'searches', 'searching', 'indexeddb'] | |
terms.forEach(function (term) { | |
tx.executeSql('select count(*) as count from doc where content match ?', | |
[term], function (tx, res) { | |
var count = res.rows.item(0).count; | |
$output.append('\nTerm "' + term + '" matches: ' + !!count); | |
}); | |
}); | |
}); | |
} | |
tx.executeSql('create virtual table doc using fts3(content text, tokenize=porter);', [], onReady, onReady); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Go gatewords