chris-yoon90 / Automated-facets

0 stars 0 forks source link

Solr with Node.js #20

Closed colinmleung closed 11 years ago

colinmleung commented 11 years ago

https://github.com/gsf/node-solr : no longer maintained https://github.com/lbdremy/solr-node-client : last commit 3 months ago, homepage: http://lbdremy.github.io/solr-node-client/

colinmleung commented 11 years ago

Installed node.js, Solr.

Used the solr-node-client and the example database provided with Solr.

Using the following node code:

var solr = require('./node_modules/solr-client/lib/solr');
var client = solr.createClient();

var querystring = require('querystring'),
    format = require('./node_modules/solr-client/lib/utils/format');

var query2 = client.createQuery()
                   .q({name : 'iPod'})
                   .start(0)
                   .rows(10);

client.search(query2,function(err,obj){
   if(err){
    console.log(err);
   }else{
    console.log(obj.response);
   }
});

RETURNS (in json format)

{ numFound: 3,
  start: 0,
  docs:
   [ { id: 'IW-02',
       name: 'iPod & iPod Mini USB 2.0 Cable',
       manu: 'Belkin',
       manu_id_s: 'belkin',
       cat: [Object],
       features: [Object],
       weight: 2,
       price: 11.5,
       price_c: '11.50,USD',
       popularity: 1,
       inStock: false,
       store: '37.7752,-122.4232',
       manufacturedate_dt: '2006-02-14T23:55:59Z',
       _version_: 1437520500077101000 },
     { id: 'F8V7067-APL-KIT',
       name: 'Belkin Mobile Power Cord for iPod w/ Dock',
       manu: 'Belkin',
       manu_id_s: 'belkin',
       cat: [Object],
       features: [Object],
       weight: 4,
       price: 19.95,
       price_c: '19.95,USD',
       popularity: 1,
       inStock: false,
       store: '45.18014,-93.87741',
       manufacturedate_dt: '2005-08-01T16:30:25Z',
       _version_: 1437520500072906800 },
     { id: 'MA147LL/A',
       name: 'Apple 60 GB iPod with Video Playback Black',
       manu: 'Apple Computer Inc.',
       manu_id_s: 'apple',
       cat: [Object],
       features: [Object],
       includes: 'earbud headphones, USB cable',
       weight: 5.5,
       price: 399,
       price_c: '399.00,USD',
       popularity: 10,
       inStock: true,
       store: '37.7752,-100.0232',
       manufacturedate_dt: '2005-10-12T08:00:00Z',
       _version_: 1437520500087586800 } ] }