2017-08-04 52 views

回答

1

您可以使用solr-node npm打包,配置起來非常簡單。這裏正在從nodesjs呼籲Solr的和Solr的獲取數據的例子

var SolrNode = require('solr-node'); 
    var client = new SolrNode({ 
     host: '<your host>', 
     port: '8983', 
     core: 'products', 
     protocol: 'http' 
    }); 
    const express = require('express'); 
    const app = express(); 
app.get('/getProduct', 
function (req, res) 
{ 
var strQuery = client.query().q('productId:9788700075740'); 
client.search(strQuery, function (err, result) { 
    if (err) { 
     console.log(err); 
     return; 
    } 
    console.log('Response:', result.response); 
    res.send(result.response); 
}); 
}); 
app.listen(3000, 
function() { 
console.log('Example app listening on port 3000!') }); 

您可以探索Solr的節點上NPM https://www.npmjs.com/package/solr-node

+0

'npm install solr-client'停在bignumber.js讀取,我已經知道如何連接solr和node-solr,謝謝無論如何,我會發布我的答案immedialy – XieWilliam

+0

@XieWilliam它的Solr節點代碼不是solr-client if你想用它使用npm安裝solr-node進行安裝 –

1
var solr = require('solr') 
var options = { 
    host: '127.0.0.1', 
    port: '8080', 
    core: 'bt', // if defined, should begin with a slash 
    path: '/solr/' // should also begin with a slash 
}; 
// Create a client 
var solrClient = solr.createClient(options); 

把這個選項在solr.createClient解決我的問題