Skip to content

Instantly share code, notes, and snippets.

@Kevinlearynet
Created December 17, 2014 17:41
Show Gist options
  • Save Kevinlearynet/c1ca04a6faa2c3f06bb0 to your computer and use it in GitHub Desktop.
Save Kevinlearynet/c1ca04a6faa2c3f06bb0 to your computer and use it in GitHub Desktop.
Example of using 'solr-client' in Node.js environment
// install solr client package: `npm install solr --save`
var solr = require( 'solr-client' );
// client connects to solr host
var client = solr.createClient({
host : host,
port : port,
core : core,
path : path,
agent : agent,
secure : secure,
bigint : bigint
});
// search query (DixMax)
var query = client.createQuery()
.q( '%keywords%' )
.dismax()
.qf( {
title_t: 0.2,
description_t: 3.3
} )
.mm( 2 )
.start( 0 )
.rows( 10 );
// run search
client.search( query, function ( err, obj ) {
if ( err ) {
console.log( err );
} else {
console.log( obj );
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment