Skip to content

Instantly share code, notes, and snippets.

@quickredfox
Created May 30, 2012 16:21
Show Gist options
  • Save quickredfox/2837388 to your computer and use it in GitHub Desktop.
Save quickredfox/2837388 to your computer and use it in GitHub Desktop.
var TermGroup;
TermGroup = function(options) {
this.name = options.name || ("termgroup-" + (new Date().getTime()));
this.terms = options.terms || [];
this.toString = function() {
return this.terms.join();
};
this.toJSON = function() {
return this.terms;
};
this.toHTML = function() {
return "<ul class=\"termgroup\">\n <li>" + this.terms.join("</li>\n <li>") + "</li>\n</ul>";
};
this.toQuery = function(orand) {
if (orand == null) orand = 'OR';
return "(" + this.terms.map(function(term) {
if (/\s/.test(term)) return '\\"' + term + '\\"';
return term;
}).join(" " + orand + " ") + ")";
};
this.getLength = function() {
return this.terms.length;
};
return this;
};
TermGroup.create = function(options) {
return new TermGroup(options);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment