{"action":"created","issue":{"url":"https://api.github.com/repos/fergiemcdowall/search-index/issues/88","labels_url":"https://api.github.com/repos/fergiemcdowall/search-index/issues/88/labels{/name}","comments_url":"https://api.github.com/repos/fergiemcdowall/search-index/issues/88/comments","events_url":"https://api.github.com/repos/fergiemcdowall/search-index/issues/88/events","html_url":"https://github.com/fergiemcdowall/search-index/issues/88","id":67672857,"number":88,"title":"can't get si.add to work without options defined before requiring search-index","user":{"login":"eklem","id":236656,"avatar_url":"https://avatars.githubusercontent.com/u/236656?v=3","gravatar_id":"","url":"https://api.github.com/users/eklem","html_url":"https://github.com/eklem","followers_url":"https://api.github.com/users/eklem/followers","following_url":"https://api.github.com/users/eklem/following{/other_user}","gists_url":"https://api.github.com/users/eklem/gists{/gist_id}","starred_url":"https://api.github.com/users/eklem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eklem/subscriptions","organizations_url":"https://api.github.com/users/eklem/orgs","repos_url":"https://api.github.com/users/eklem/repos","events_url":"https://api.github.com/users/eklem/events{/privacy}","received_events_url":"https://api.github.com/users/eklem/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/fergiemcdowall/search-index/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-10T20:12:34Z","updated_at":"2015-04-10T20:14:59Z","closed_at":null,"body":"If i do like this:\r\n```javascript\r\nvar si = require('search-index')\r\n\r\nvar batch = [\r\n  {\r\n    'id':'1',\r\n    'title':'A really interesting document',\r\n    'body':'This is a really interesting document',\r\n    'metadata':['red', 'potato']\r\n  },\r\n  {\r\n    'id':'2',\r\n    'title':'Another interesting document',\r\n    'body':'This is another really interesting document that is a bit different',\r\n    'metadata':['yellow', 'potato']\r\n  }\r\n];\r\nvar batchName = 'twoDocs';\r\nvar filters = ['metadata'];\r\n\r\nsi.add({'batchName': batchName, 'filters': filters}, batch, function(err) {\r\n  if (!err) console.log('indexed!');\r\n});\r\n```\r\n... I get this error:\r\n```javascript\r\nsi.add({'batchName': batchName, 'filters': filters}, batch, function(err) {\r\n   ^\r\nTypeError: Object function SearchIndex(options) {\r\n  if (!(this instanceof SearchIndex))\r\n    return new SearchIndex(options);\r\n  //------------libs\r\n  this.level = require('levelup');\r\n  this.levelMultiply = require('level-multiply');\r\n  this.winston = require('winston');\r\n  _ = require('lodash');\r\n  this.defaults = {\r\n    indexPath: 'si',\r\n    logLevel: 'info',\r\n    logSilent: false\r\n  };\r\n  //initialize defaults options\r\n  this.options = _.defaults(options || {}, this.defaults);\r\n  this.calibrater = require('./indexing/calibrater.js');\r\n  this.deleter = require('./indexing/deleter.js');\r\n  this.docGetter = require('./search/docGetter.js');\r\n  this.indexPeek = require('./indexing/indexPeek.js');\r\n  this.indexer = require('./indexing/indexer.js');\r\n  this.matcher = require('./matchers/matcher.js');\r\n  this.replicator = require('./indexing/replicator.js');\r\n  this.searcher = require('./search/searcher.js');\r\n  this.searchIndexLogger = require('./logger/searchIndexLogger');\r\n  this.indexes = (this.options && this.options.db)\r\n    ? this.level(this.options.indexPath, {valueEncoding: 'json', db: this.options.db})\r\n    : this.level(this.options.indexPath, {valueEncoding: 'json'});\r\n  this.indexesMultiply = this.levelMultiply(this.indexes);\r\n  this.searchIndexLogger.remove(this.winston.transports.Console);\r\n  this.searchIndexLogger.add(this.winston.transports.Console, {silent: this.options.logSilent, level: this.options.logLevel});\r\n  //is there a better way of doing this?\r\n  var searcher = this.searcher;\r\n  this.calibrater.getTotalDocs(this.indexes, function(err, totalDocs) {\r\n    searcher.setTotalDocs(totalDocs);\r\n  });\r\n} has no method 'add'\r\n    at Object.<anonymous> (/Users/eklem/node_modules/life-indexer/test.js:20:4)\r\n    at Module._compile (module.js:456:26)\r\n    at Object.Module._extensions..js (module.js:474:10)\r\n    at Module.load (module.js:356:32)\r\n    at Function.Module._load (module.js:312:12)\r\n    at Function.Module.runMain (module.js:497:10)\r\n    at startup (node.js:119:16)\r\n    at node.js:929:3\r\n```\r\n\r\nBut if change the start of the file to this:\r\n```javascript\r\nvar options = { indexPath: 'si2', logLevel: 'info', logSilent: false }\r\nvar si = require('search-index')(options)\r\n```\r\n...everything works okay! It's a minor since it's possible to work around pretty easy."},"comment":{"url":"https://api.github.com/repos/fergiemcdowall/search-index/issues/comments/91672599","html_url":"https://github.com/fergiemcdowall/search-index/issues/88#issuecomment-91672599","issue_url":"https://api.github.com/repos/fergiemcdowall/search-index/issues/88","id":91672599,"user":{"login":"eklem","id":236656,"avatar_url":"https://avatars.githubusercontent.com/u/236656?v=3","gravatar_id":"","url":"https://api.github.com/users/eklem","html_url":"https://github.com/eklem","followers_url":"https://api.github.com/users/eklem/followers","following_url":"https://api.github.com/users/eklem/following{/other_user}","gists_url":"https://api.github.com/users/eklem/gists{/gist_id}","starred_url":"https://api.github.com/users/eklem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eklem/subscriptions","organizations_url":"https://api.github.com/users/eklem/orgs","repos_url":"https://api.github.com/users/eklem/repos","events_url":"https://api.github.com/users/eklem/events{/privacy}","received_events_url":"https://api.github.com/users/eklem/received_events","type":"User","site_admin":false},"created_at":"2015-04-10T20:14:59Z","updated_at":"2015-04-10T20:14:59Z","body":"And kudos for good examples, so it's easy to test for bugs and issues!"}}