Hi all,
I spent part of the day today to build an initial naive version of
full-text search for persistence.js. To use it simply include
persistence.search.js after including persistence.js.
Example usage:
var Note = persistence.define('Note', {
name: "TEXT",
text: "TEXT",
status: "TEXT"
});
Note.textIndex('name');
Note.textIndex('text');
This sample defines a `Note` entity with three properties of which
`name` and `text` are full-text indexed. For this a new database table
will be created that stores the index.
Searching is done as follows:
Note.search({query: "note", success: function(results) {
console.log(results);
}});
or you can paginate your results using `limit` and `skip` (similar
to `limit` and `skip` in QueryCollections).
Note.search({query: "note", limit: 10, skip: 10, success:
function(results) {
console.log(results);
}});
Query language
--------------
Queries can contain regular words. In addition the `*` wildcard can be
used anywhere with a word. The `property:` notation can be used to
search only a particular field. Examples:
* `note`
* `name: note`
* `interesting`
* `inter*`
* `important essential`
Note that currently a result is return when _any_ word matches.
Results are ranked by number of occurences of one of the words in the
text.
For each table with a textIndex column there is another
TableName_Index table created that contains the index. This table
format is not optimal at this point, it contains the UUID of the
entity, the property name, the word and the occurrence count. This
could be further optimized to reduce storage size. I implemented
_extremely_ simple stemming for English words (basically removing -s
endings from words and replacing -ies with -y, so that'd you find
babies when searching for baby, and vice versa).
Note that the API style diverged a bit from the rest of persistence.js
(passing an object containing named arguments to search, rather than a
flat list of arguments). Fabio will (hopefully) send a proposal for
applying this style to the rest of persistence.js later this week.
As usual, it's all available from
http://github.com/zefhemel/persistencejs
For now, what do you guys think? Any comments?
Best,
Zef
--
Zef Hemel
http://zef.me
http://twitter.com/zef
--
Subscription settings:
http://groups.google.com/group/persistencejs/subscribe?hl=en