Permalink
Browse files

Initial commit, nothing much to see.

Signed-off-by: Nick Campbell <nicholas.j.campbell@gmail.com>
  • Loading branch information...
0 parents commit 0ac8b21ca85dc699a8030f781630c043d87823b7 @ncb000gt committed Mar 1, 2011
Showing with 64 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +5 −0 index.js
  3. +25 −0 lib/elasticsearch.js
  4. +14 −0 lib/query.js
  5. +18 −0 tests/test-query.js
@@ -0,0 +1,2 @@
+*.swp
+*.swo
@@ -0,0 +1,5 @@
+var es = require('./lib/elasticsearch'),
+query = require('./lib/query');
+
+module.exports['search'] = es;
+module.exports['query'] = query;
@@ -0,0 +1,25 @@
+var http = require('http');
+
+function ElasticSearch(opts) {
+ this.config = {
+ host: 'localhost',
+ port: '9200'
+ };
+ if (!(opts.index)) {
+ throw new Error('Must specify an index for ES.');
+ }
+ for (var p in opts) {
+ this.config[p] = opts[p];
+ }
+}
+
+module.exports = ElasticSearch;
+
+ElasticSearch.prototype.query = function(query, cb) {
+ var options = {
+ host: this.config.host,
+ port: this.config.port,
+ method: 'POST'
+ };
+ http.request();
+}
@@ -0,0 +1,14 @@
+function Query() {
+ this.query = {query:{}};
+}
+
+module.exports = Query;
+
+Query.prototype.addField = function(name, field) {
+ if (!(this.query.query.field)) {
+ this.query.query.field = {};
+ }
+ this.query.query.field[name] = field;
+
+ return this;
+}
@@ -0,0 +1,18 @@
+var es = require('../index'),
+ assert = require('assert');
+
+module.exports = {
+ 'add field': function() {
+ var field = {query: 'text'}, name = 'test';
+ var def = {query: {field: {'test': field}}};
+
+ assert.deepEqual((new es.query()).addField(name, field).query, def);
+ },
+ 'add fields chained': function() {
+ var field1 = {query: 'text'}, name = 'test1',field2 = {query: 'text'}, name2 = 'test2';
+ var def = {query: {field: {'test1': field1, 'test2': field2}}};
+
+ var new_query = (new es.query()).addField(name, field1).addField(name2, field2);
+ assert.deepEqual(new_query.query, def);
+ }
+};

0 comments on commit 0ac8b21

Please sign in to comment.