Solr client for node.js

A solr client for indexing, adding, deleting,committing and searching documents within an Apache Solr installation (version>=3.2).

Latest Update from Github

Loading...
Loading...

Search documents with DisMax query or Lucene query

Hide Source
// Use `var solr = require('solr-client')` in your code
var solr = require('./../lib/solr');

var client = solr.createClient();

// DixMax query
var query = client.createQuery()
				  .q('laptop')
				  .dismax()
				  .qf({title_t : 0.2 , description_t : 3.3})
				  .mm(2)
				  .start(0)
				  .rows(10);
client.search(query,function(err,obj){
   if(err){
   	console.log(err);
   }else{
   	console.log(obj);
   }
});

// Lucene query
var query2 = client.createQuery()
				   .q({title_t : 'laptop'})
				   .start(0)
				   .rows(10);
client.search(query2,function(err,obj){
   if(err){
   	console.log(err);
   }else{
   	console.log(obj);
   }
});

EdisMax Query

query3

@see

You can use edismax query parser It will set the defType as edismax

Hide Source
var query3 = client.createQuery()
              .q('laptop')
              .edismax()
              .qf({title_t : 0.2 , description_t : 3.3})
              .mm(2)
              .start(0)
              .rows(10);

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

boost()

query4

@see

You can use boost() query in order to manipulate solr score boost() is the multiplicative version of bf() which is additive To use boost() do not forget edismax()

Hide Source
var query4 = client.createQuery()
              .q('laptop')
              .edismax()
              .qf({title_t : 0.2 , description_t : 3.3})
              .boost('3') // you can also use `solr` functions, like `.boost('product(score_title, 3)')`
              .mm(2)
              .start(0)
              .rows(10);

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