Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changing keyword options and method name.

  • Loading branch information...
commit e11e4fdf94389d93a0748919fbdd38b74f5f4385 1 parent b596378
@sorensen sorensen authored
Showing with 53 additions and 48 deletions.
  1. +10 −1 index.js
  2. +0 −37 lib/extractKeywords.js
  3. +0 −10 lib/index.js
  4. +43 −0 lib/keywords.js
View
11 index.js
@@ -1 +1,10 @@
-module.exports = require('./lib')
+
+/*!
+ * Analytics Machine - Plugins
+ * Copyright(c) Thomas Blobaum
+ * MIT Licensed
+ */
+
+require('directory')(__dirname + '/lib/', function (fn, filename) {
+ module.exports[filename] = fn
+})
View
37 lib/extractKeywords.js
@@ -1,37 +0,0 @@
-
-/*!
- * Copyright(c) Beau Sorensen
- * MIT Licensed
- */
-
-module.exports = function(schema, options) {
- options || (options = {})
-
- var target = options.target
- , source = options.source
-
- schema
- .pre('save', function(next) {
- var words = []
-
- if (!(source instanceof Array)) source = [source]
-
- for (var i = 0; i < source.length; i++) {
- var add = this.extractKeywords(this[source[i]])
- for (var s = 0; s < add.length; s++) {
- if (!~words.indexOf(ext[s])) words.push(add[s])
- }
- }
- this[target] = words
- next()
- })
-
- schema.method('extractKeywords', function (str) {
- if (!str) return []
- return str
- .toLowerCase()
- .split(/\s+/)
- .filter(function(v) { return v.length > 2 })
- .filter(function(v, i, a) { return a.lastIndexOf(v) === i })
- })
-}
View
10 lib/index.js
@@ -1,10 +0,0 @@
-
-/*!
- * Analytics Machine - Plugins
- * Copyright(c) Thomas Blobaum
- * MIT Licensed
- */
-
-require('directory')(function (fn, filename) {
- module.exports[filename] = fn
-})
View
43 lib/keywords.js
@@ -0,0 +1,43 @@
+
+/*!
+ * Copyright(c) Beau Sorensen
+ * MIT Licensed
+ */
+
+module.exports = function(schema, options) {
+ options || (options = {})
+
+ var target = (options.target || 'keywords')
+ , source = options.source
+ , minLength = (options.minLength || 2)
+ , fields = {}
+
+ if (!schema.paths[target]) {
+ fields[target] = [String]
+ schema.add(fields)
+ }
+
+ schema
+ .pre('save', function(next) {
+ var words = []
+ if (!(source instanceof Array)) source = [source]
+ for (var i = 0; i < source.length; i++) {
+ var add = this.extractKeywords(this[source[i]])
+ for (var s = 0; s < add.length; s++) {
+ if (!~words.indexOf(add[s])) words.push(add[s])
+ }
+ }
+ this[target] = words
+ next()
+ })
+
+ schema
+ .method('extractKeywords', function (str) {
+ if (!str) return []
+ return str
+ .toLowerCase()
+ .split(/\s+/)
+ .filter(function(v) { return v.length > minLength })
+ .filter(function(v, i, a) { return a.lastIndexOf(v) === i })
+ })
+}
Please sign in to comment.
Something went wrong with that request. Please try again.