如何将solr与nodejs连接?

时间:2017-08-04 07:12:07

标签: node.js solr

我跟着https://github.com/gsf/node-solr,用

安装了node-solr
npm install solr

然后如何在8080端口连接solr?

3 个答案:

答案 0 :(得分:2)

你可以使用solr-node npm packege配置起来非常简单。这是从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!') });

你可以在npm https://www.npmjs.com/package/solr-node

上探索solr-node

答案 1 :(得分: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解决了我的问题

答案 2 :(得分:0)

我使用Solr-client作为节点js。

npm install --save solr-client

// Load dependency
var solr = require('solr-client');

// Create a client
var client = solr.createClient();

// Add a new document
client.add({ id : 12, title_t : 'Hello' },function(err,obj){
   if(err){
      console.log(err);
   }else{
      console.log('Solr response:', obj);
   }
});
相关问题