Home

Awesome

backlunr

is a solution to bring Backbone Collections together with the browser fulltext search engine Lunr.js.

INFO: all examples are written in coffee-script

Install

To use backlunr you first have to load the dependencies:

Then add the backlunr.js script to your page.

Usage

Config

To use the lunr.js fulltext search within a collection you have to load backlunr.js and use Backbone.Collection.Lunr instead of Backbone.Collection

The only thing you have to define are the fields to index.

Config Example:

class User extends Backbone.Model

class Users extends Backbone.Collection.Lunr
	model: User
	lunroptions:
		fields: [
			{ name: "firstname", boost: 10 }
			{ name: "lastname", boost: 5 }
			{ name: "email" }
			{ name: "address" }
		]

lunroptions

Attension: Currently Lunr.js does not support an indexing of numeric values. To use numeric values backlunr converts all fields to strings.

search

To search within your collection you just have to call .search( "[ term ]" ).

Search Example:

# add some users
usersCollection = new Users [
	firstname: "Fritz", lastname: "Maier", "email": "fmaier@maier.com", "address": "Teststreet 123"
,
	firstname: "Hans", lastname: "Schubert", "email": "hschubert@maier.com", "address": "Checkway 987"
]

result = usersCollection.search( "Fritz" )
# [ User( Fritz ) ]
# returns an array of matching models sorted by the result scoring

result.toJSON()
# [ {firstname: "Fritz", lastname: "Maier", "email": "fmaier@maier.com", "address": "Teststreet 123"} ]
# the single special method `toJSON` of the array returns all models converted by `model.toJSON()`.

Methods

Collection.search( term [, raw ] )

.search() is the only method added to the collection by Backlunr.

arguments:

retuns ( Array ):

An array of matching models.
If you define raw=true you will receive an array with object like { score: 0.789, ref: "c123" }

Ideas

Work in progress

backlunr is work in progress. Your ideas, suggestions etc. are very welcome.

Development

If you want to contribute you have to install the dependencies and gulp as task runner:

$ npm install
$ npm install -g gulp

After that it's possible to build the code using

$ gulp

Changelog

0.3.0

0.2.5

0.2.4

0.2.3

0.2.2

0.2.1

0.2.0

0.1.0

Todo

Other projects

NameDescription
node-cacheSimple and fast NodeJS internal caching. Node internal in memory cache like memcached.
rsmqA really simple message queue based on redis
redis-heartbeatPulse a heartbeat to redis. This can be used to detach or attach servers to nginx or similar problems.
systemhealthNode module to run simple custom checks for your machine or it's connections. It will use redis-heartbeat to send the current state to redis.
rsmq-clia terminal client for rsmq
rest-rsmqREST interface for.
nsq-loggerNsq service to read messages from all topics listed within a list of nsqlookupd services.
nsq-topicsNsq helper to poll a nsqlookupd service for all it's topics and mirror it locally.
nsq-nodesNsq helper to poll a nsqlookupd service for all it's nodes and mirror it locally.
nsq-watchWatch one or many topics for unprocessed messages.
redis-sessionsAn advanced session store for NodeJS and Redis
connect-redis-sessionsA connect or express middleware to simply use the redis sessions. With redis sessions you can handle multiple sessions per user_id.
redis-notificationsA redis based notification engine. It implements the rsmq-worker to safely create notifications and recurring reports.
hyperrequestA wrapper around hyperquest to handle the results
task-queue-workerA powerful tool for background processing of tasks that are run by making standard http requests
soyerSoyer is small lib for server side use of Google Closure Templates with node.js.
grunt-soy-compileCompile Goggle Closure Templates ( SOY ) templates including the handling of XLIFF language files.
backlunrA solution to bring Backbone Collections together with the browser fulltext search engine Lunr.js
domelA simple dom helper if you want to get rid of jQuery
obj-schemaSimple module to validate an object by a predefined schema

License

(The MIT License)

Copyright (c) 2010 TCS <dev (at) tcs.de>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.