vineyard-solr
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -7,4 +7,4 @@ var __extends = this.__extends || function (d, b) { | ||
}; | ||
var MetaHub = require('metahub'); | ||
var Ground = require('ground'); | ||
var MetaHub = require('vineyard-metahub'); | ||
var Ground = require('vineyard-ground'); | ||
var Vineyard = require('vineyard'); | ||
@@ -22,4 +22,4 @@ var when = require('when'); | ||
"prepare": function (filter, property) { | ||
var url = property.parent.name + '/select?q=' + property.name + ':*' + filter.value + '*&wt=json'; | ||
console.log('solr-query', url); | ||
var url = _this.get_core() + '/select?q=' + property.name + ':*' + encodeURIComponent(filter.value) + '*&wt=json'; | ||
return _this.get_json(url).then(function (response) { | ||
@@ -34,3 +34,3 @@ var trellis = property.parent; | ||
var ids = docs.map(function (doc) { | ||
return primary.get_sql_value(doc.guid); | ||
return primary.get_sql_value(doc[trellis.primary_key]); | ||
}); | ||
@@ -50,2 +50,3 @@ filter.value = ids.join(', '); | ||
var solr_trellis = config.trellises[i]; | ||
solr_trellis.core = solr_trellis.core || i; | ||
var query_builder = new Ground.Query_Builder(this.ground.trellises[i]); | ||
@@ -66,3 +67,3 @@ query_builder.extend(solr_trellis.query); | ||
if (solr_trellis.suggestions) | ||
lawn.listen_public_http('/vineyard/solr/' + i + '/suggest', function (req, res) { | ||
lawn.listen_public_http('/vineyard/solr/' + _this.get_core() + '/suggest', function (req, res) { | ||
return _this.suggest(req, res, i); | ||
@@ -75,4 +76,9 @@ }, 'get'); | ||
Solr.prototype.get_core = function () { | ||
var config = this.config; | ||
return config.server.core; | ||
}; | ||
Solr.prototype.suggest = function (req, res, trellis_name) { | ||
var url = trellis_name + '/suggest?q=' + req.query['q'] + '&wt=json'; | ||
var url = this.get_core() + '/suggest?q=' + encodeURIComponent(req.query['q']) + '&wt=json'; | ||
return this.get_json(url).then(function (response) { | ||
@@ -95,3 +101,3 @@ var suggestions = []; | ||
var config = this.config; | ||
var server = config.solr_server; | ||
var server = config.server; | ||
var def = when.defer(); | ||
@@ -142,3 +148,3 @@ var http = require('http'); | ||
var config = this.config; | ||
var server = config.solr_server; | ||
var server = config.server; | ||
var def = when.defer(); | ||
@@ -154,20 +160,19 @@ var http = require('http'); | ||
var req = http.request(options, function (res) { | ||
if (res.statusCode != '200') { | ||
res.setEncoding('utf8'); | ||
res.on('data', function (chunk) { | ||
console.log('client received an error:', res.statusCode, chunk); | ||
def.reject(); | ||
}); | ||
} else { | ||
var buffer = ''; | ||
res.on('data', function (chunk) { | ||
buffer += chunk; | ||
}); | ||
res.setEncoding('utf8'); | ||
var buffer = ''; | ||
res.on('data', function (chunk) { | ||
buffer += chunk; | ||
}); | ||
res.on('end', function () { | ||
res.on('end', function () { | ||
if (buffer.length > 0) | ||
res.content = JSON.parse(buffer); | ||
if (res.statusCode != '200') { | ||
console.log('client received an error:', res.statusCode, buffer); | ||
def.reject(); | ||
} else { | ||
def.resolve(res); | ||
}); | ||
} | ||
} | ||
}); | ||
}); | ||
@@ -185,4 +190,4 @@ | ||
Solr.prototype.post_update = function (trellis_name, data) { | ||
return this.post(trellis_name + '/update/json?commit=true', data); | ||
Solr.prototype.post_update = function (data) { | ||
return this.post(this.get_core() + '/update/json?commit=true', data); | ||
}; | ||
@@ -192,3 +197,3 @@ | ||
var _this = this; | ||
return this.clear_all().then(function () { | ||
return this.clear().then(function () { | ||
return _this.perform_on_all_trellises(function (name) { | ||
@@ -213,14 +218,6 @@ return _this.create_update(name); | ||
Solr.prototype.clear = function (trellis_name) { | ||
console.log('clearing', trellis_name); | ||
return this.post(trellis_name + '/update?commit=true', '<delete><query>*:*</query></delete>', 'xml'); | ||
Solr.prototype.clear = function () { | ||
return this.post(this.get_core() + '/update?commit=true', '<delete><query>*:*</query></delete>', 'xml'); | ||
}; | ||
Solr.prototype.clear_all = function () { | ||
var _this = this; | ||
return this.perform_on_all_trellises(function (name) { | ||
return _this.clear(name); | ||
}); | ||
}; | ||
Solr.prototype.create_update = function (trellis_name) { | ||
@@ -230,3 +227,3 @@ var _this = this; | ||
console.log('update-solr', trellis_name, JSON.stringify(updates)); | ||
return _this.post_update(trellis_name, updates); | ||
return _this.post_update(updates); | ||
}); | ||
@@ -245,3 +242,3 @@ }; | ||
console.log('update-solr2', trellis_name, JSON.stringify(update)); | ||
return this.post_update(trellis_name, [update]); | ||
return this.post_update([update]); | ||
}; | ||
@@ -248,0 +245,0 @@ |
@@ -13,6 +13,7 @@ /// <reference path="../../vineyard/vineyard.d.ts"/> | ||
path?:string | ||
core:string | ||
} | ||
interface Solr_Config { | ||
solr_server:Solr_Server_Config | ||
server:Solr_Server_Config | ||
trellises | ||
@@ -24,2 +25,3 @@ } | ||
suggestions:boolean | ||
core?:string | ||
} | ||
@@ -32,6 +34,7 @@ | ||
"prepare": (filter, property):Promise => { | ||
var url = property.parent.name + '/select?q=' + property.name + ':*' + filter.value + '*&wt=json' | ||
console.log('solr-query', url) | ||
var url = this.get_core() + '/select?q=' + property.name + ':*' + encodeURIComponent(filter.value) + '*&wt=json' | ||
// console.log('solr-query', url) | ||
return this.get_json(url) | ||
.then((response) => { | ||
// console.log('solr result', response) | ||
var trellis = property.parent | ||
@@ -44,3 +47,3 @@ var primary = trellis.properties[trellis.primary_key] | ||
var ids = docs.map((doc)=> primary.get_sql_value(doc.guid)) | ||
var ids = docs.map((doc)=> primary.get_sql_value(doc[trellis.primary_key])) | ||
filter.value = ids.join(', ') | ||
@@ -59,2 +62,3 @@ }) | ||
var solr_trellis = <Solr_Trellis>config.trellises[i] | ||
solr_trellis.core = solr_trellis.core || i | ||
var query_builder = new Ground.Query_Builder(this.ground.trellises[i]) | ||
@@ -67,4 +71,2 @@ query_builder.extend(solr_trellis.query) | ||
) | ||
} | ||
@@ -78,3 +80,4 @@ | ||
if (solr_trellis.suggestions) | ||
lawn.listen_public_http('/vineyard/solr/' + i + '/suggest', (req, res)=> this.suggest(req, res, i), 'get') | ||
lawn.listen_public_http('/vineyard/solr/' + this.get_core() + '/suggest', | ||
(req, res)=> this.suggest(req, res, i), 'get') | ||
} | ||
@@ -85,4 +88,9 @@ }) | ||
get_core():string { | ||
var config = <Solr_Config>this.config | ||
return config.server.core | ||
} | ||
suggest(req, res, trellis_name:string):Promise { | ||
var url = trellis_name + '/suggest?q=' + req.query['q'] + '&wt=json' | ||
var url = this.get_core() + '/suggest?q=' + encodeURIComponent(req.query['q']) + '&wt=json' | ||
return this.get_json(url) | ||
@@ -105,3 +113,3 @@ .then((response)=> { | ||
var config = <Solr_Config>this.config | ||
var server = config.solr_server | ||
var server = config.server | ||
var def = when.defer() | ||
@@ -153,3 +161,3 @@ var http = require('http') | ||
var config = <Solr_Config>this.config | ||
var server = config.solr_server | ||
var server = config.server | ||
var def = when.defer() | ||
@@ -165,21 +173,20 @@ var http = require('http') | ||
var req = http.request(options, function (res) { | ||
if (res.statusCode != '200') { | ||
res.setEncoding('utf8') | ||
res.on('data', function (chunk) { | ||
console.log('client received an error:', res.statusCode, chunk) | ||
def.reject() | ||
}) | ||
} | ||
else { | ||
var buffer = '' | ||
res.on('data', function (chunk) { | ||
buffer += chunk | ||
}) | ||
res.setEncoding('utf8') | ||
var buffer = '' | ||
res.on('data', function (chunk) { | ||
buffer += chunk | ||
}) | ||
res.on('end', function () { | ||
res.on('end', function () { | ||
if (buffer.length > 0) | ||
res.content = JSON.parse(buffer) | ||
// console.log('response2', res.content) | ||
if (res.statusCode != '200') { | ||
console.log('client received an error:', res.statusCode, buffer) | ||
def.reject() | ||
} | ||
else { | ||
def.resolve(res) | ||
}) | ||
} | ||
} | ||
}) | ||
}) | ||
@@ -197,8 +204,8 @@ | ||
post_update(trellis_name:string, data):Promise { | ||
return this.post(trellis_name + '/update/json?commit=true', data) | ||
post_update(data):Promise { | ||
return this.post(this.get_core() + '/update/json?commit=true', data) | ||
} | ||
rebuild_indexes():Promise { | ||
return this.clear_all() | ||
return this.clear() | ||
.then(()=> | ||
@@ -222,13 +229,6 @@ this.perform_on_all_trellises((name)=> | ||
clear(trellis_name:string):Promise { | ||
console.log('clearing', trellis_name) | ||
return this.post(trellis_name + '/update?commit=true', '<delete><query>*:*</query></delete>', 'xml') | ||
clear():Promise { | ||
return this.post(this.get_core() + '/update?commit=true', '<delete><query>*:*</query></delete>', 'xml') | ||
} | ||
clear_all():Promise { | ||
return this.perform_on_all_trellises((name)=> | ||
this.clear(name) | ||
) | ||
} | ||
create_update(trellis_name:string):Promise { | ||
@@ -238,3 +238,3 @@ return this.create_trellis_updates(trellis_name) | ||
console.log('update-solr', trellis_name, JSON.stringify(updates)) | ||
return this.post_update(trellis_name, updates) | ||
return this.post_update(updates) | ||
}) | ||
@@ -253,3 +253,3 @@ } | ||
console.log('update-solr2', trellis_name, JSON.stringify(update)) | ||
return this.post_update(trellis_name, [ update ]) | ||
return this.post_update([ update ]) | ||
} | ||
@@ -256,0 +256,0 @@ |
{ | ||
"name": "vineyard-solr", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Solr integration for Vineyard", | ||
@@ -5,0 +5,0 @@ "main": "lib/Solr.js", |
Sorry, the diff of this file is not supported yet
47891
941