/node-solr

Solr module for Node.js

Primary LanguageJavaScriptMIT LicenseMIT

Solr module for Node.js


Node.js: http://github.com/joyent/node
Solr: http://lucene.apache.org/solr/

Run tests with `make test`. Edit "test/common.js" if you don't have Solr 
running at 127.0.0.1:8983. 

See tests for usage. Here's a quick example:

    var solr = require('solr');

    var client = solr.createClient();
    var doc1 = {
      id: '1',
      title_t: 'Foo bar',
      text_t: 'Fizz buzz frizzle'
    };
    var doc2 = {
      id: '2',
      title_t: 'Far boo',
      text_t: 'Wuzz fizz drizzle'
    };
    var callback = function(err, response) {
      if (err) throw err;
      console.log('Document added');
    };
    client.add(doc1, callback);
    client.add(doc2, callback);
    client.commit();

    var query = 'text_t:fizz'
    client.query(query, function(err, response) {
      if (err) throw err;
      var responseObj = JSON.parse(response);
      console.log('A search for "' + query + '" returned ' +
          responseObj.response.numFound + ' documents.');
      console.log('First doc title: ' + responseObj.response.docs[0].title_t);
      console.log('Second doc title: ' + responseObj.response.docs[1].title_t);
    });

    var id;
    client.del(id, query, function(err, response) {
      if (err) throw err;
      console.log('Deleted all docs matching query "' + query + '"');
    });
    client.commit()