1.1.1 • Published 9 years ago

mongotagger v1.1.1

Weekly downloads
3
License
ISC
Repository
github
Last release
9 years ago

#mongoTagger

Basic tagging and article relationship plugin for Mongoose

Please use mongoTagger 1.1.1

Creates methods to add, remove, and display tags to and for a document. As well as find models filtered by tags, and provide documents with strong relationship to original.

Note: This plugin is meant to be associated with a schema like "Articles", or "Documents", however, for full functionality, a Tag Schema must also be created and passed in as an option when the plugin is added.

##Getting Started First you'll need to npm install the plugin

$ npm install --save mongotagger

Next you'll need to require the module in your models.

mongoTagger = require("mongoTagger");

After you've created your document Schema add the plugin to it like so:

ArticleSchema.plugin(mongoTagger, Tag);

Note: that the "Tag" argument passed must be a Tags Model that has the keys "articleId" and "name".

Something like this:

var TagSchema = new Schema({
name: String,
articleId: String,
})

var Tag = mongoose.model('Tag', TagSchema);
module.exports = Tag

That's pretty much it!

##API Note: Code Examples below will use "article" as the document name and "Article" will refer to the parent model.

###model.addTag(tag, cb) Add a tag to a document, both as a nested array and as an Article_Tag_Association Hash.

article.addTag('Caz!!', function (err, tag){
if(err){
	console.log(err);
}else{
 	console.log(tag);
    }
});

The first parameter passed must be a String.

NOTE: This method modifies the database

###model.removeTag(tag) Removes a tag from a document and from the Article_Tag_Association Hash

article.removeTag('Filo!!')

The parameter passed must be a String.

NOTE: This method modifies the database

###model.displayTags(cb) Returns all of the tags associated with the document that calls it. Takes only a call back as an argument.

article.displayTags(function (err, tags){
if(err){
	console.log(err);
}else{
 	console.log(tags);
    }
});

###Model.tagFilter(includes, cb) Filters the Entire collection of documents for those with a tag or tags. The first parameter takes an Array of Strings and returns the documents which have at least one of the tags in the Array.

Article.tagFilter(function (err, docs){
if(err){
	console.log(err);
}else{
 	console.log(docs);
    }
}); 

Note: This is a Static and not an document method.

###model.relations(includes, cb) Returns Documents that are related to the document that calls it, by tags. The paramater "includes", is optional, takes an array of Strings, and returns documents related through the tags in Includes.

article.relations([includes], function (err, docs){
if(err){
	console.log(err);
}else{
 	console.log(docs);
    }
}); 

If only a call back is passed, this method will return all documents associated with the document that calls it with a "Relationship Score" associated with each. Each Documents tags will be cross referenced to the calling documents tags and the more in common, the higher the score.

###model.keywords(includes, field, cb) Returns documents that are related to the calling document by keywords. The parameter "Includes", must be an Array that contains a String, however the string can include multiple words. The parameter, "field", must be an Array that contains the Name of the Schema field to be queried, as a String.

Note: The fields to be queried must be indexed as "text". For Example to query the fullArticle field, the Schema might look like this

fullArticle: {type: [String], index: "text"}

The keyword method could then be called like this:

 article.keywords(includes, field, function (err, docs){
if(err){
	console.log(err);
}else{
 	console.log(docs);
    }
});

Note: This method does not allow for calling common english words like, "the", "to", or "a".

###Inner Keywords The Keyword method is set up to run on a document because of it's "inner keyword" functionality. When called the Method can accept the "inner keywords" as a string. When this is passed, the entire text of the associated field of an article is checked against other docs creating a more robust relationship. Along with a relationship score the Inner Keyword Method will return the words that are in common between two texts with a count of how many times the word has appeared.

For Example, this Database Call:

article.keywords( ["inner keywords"], ['full'], function (err, docs){
		if(err){
			console.log(err);
		}else{
			console.log(docs[0].commonWords);
		}
	})  

Would yeild something like this:

[ { full: [ 'The series whose second season began airing last week depicts the gloveless hands of surgeons aggressively exploring all three of these daunting body cavities. It’s this bloody medical realism, set to a minimalist score ...' ],
  tags: [ 'filo!!' ],
  __v: 1,
  source: 'Sun',
  author: 'C.W. Gaffney',
  title: 'Concateny',
  _id: 562fbe73e762c0ceaf2d6a28 },
{ score: 5 },
commonWords: { began: 1, hands: 1, medical: 2} ] 

##ToDos

  • Add a key-word-search relations method that will provide a prioritized list of documents based on key words in the text.

  • Add a count for each common word when using the Keyword Method.

  • Add sort for common words.

  • refactor relations method so larger database searches use only the join table and then populate the selected documents.

  • Normalize text input.

1.1.1

9 years ago

1.1.0

9 years ago

1.0.9

9 years ago

1.0.8

9 years ago

1.0.7

9 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago