Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var IndexTankCollection = IndexTankService.extend({
- /**
- */
- 'override __construct': function(config, name)
- {
- this._super(config);
- this.name = name;
- this._insertBatch = [];
- this._lazyInsertCallback = lazyCallback(this.getMethod('_insertDocBatch'), 500)
- },
- /**
- * adds to the collection
- */
- 'create': function(callback)
- {
- this._put(this._getIndexUrl(), callback);
- },
- /**
- * removes the collection
- */
- 'remove': function(callback)
- {
- this._delete(this._getIndexUrl(), callback);
- },
- /**
- * returns the metadata of given collection
- */
- 'getMetadata': function(callback)
- {
- this._get(this._getIndexUrl(), callback);
- },
- /**
- * adds a document to the index
- * @ops
- * - @docid the document identifier
- * - @fields a map from field name to field value
- * - @variables a map of the var number to float
- * - @categories a map from the category name to its value
- */
- 'addDoc': function(ops, callback)
- {
- if(ops.fields._id)
- {
- ops.docid = ops.fields._id.toString();
- delete ops.fields._id;
- }
- //send batch collections
- this._insertBatch.push(ops);
- //start the insertion process
- this._lazyInsertCallback();
- },
- /**
- * removes a doc
- */
- 'removeDoc': function(docid, callback)
- {
- this._delete(this._getIndexUrl() + '/docs', JSON.stringify({ docid: docid }), callback);
- },
- /**
- * searches for a document
- * @ops
- * - @q the query string
- * - @len the number of items to return
- * - @function the the number of scoring function to use
- * - @fetch comma-separated list of fields to fetch. * returns all
- * - @snippet comma-separated list of fields to snippet
- * - @var<n> value of query variable
- * - @category_filters json map of categoriy name
- * - @filter_docvar comma-separated list of ranges to filter
- * - @filter_function comma-separated list of ranges to filter the values of functions.
- */
- 'search': function(ops, callback)
- {
- this._get(this._getIndexUrl() + '/search', ops, callback);
- },
- /**
- * promotes item to the top of the query's result page
- */
- 'promote': function(docid, query)
- {
- this._put(this._getIndexUrl() + '/promote', { docid: docid, query: query }, function()
- {
- });
- },
- /**
- */
- 'autoComplete': function(query, callbackString, callback)
- {
- this._get(this._getIndexUrl() + '/autocomplete', {query: query, callback: callbackString }, callback);
- },
- /**
- * inserts a batch of documents
- */
- '_insertDocBatch': function()
- {
- var batch = this._insertBatch;
- this._insertBatch = [];
- this._put(this._getIndexUrl() + '/docs', JSON.stringify(batch), function()
- {
- console.log("INSERTED")
- });
- },
- /**
- * returns the index url
- */
- '_getIndexUrl': function()
- {
- return '/indexes/' + this.name;
- }
- });
Add Comment
Please, Sign In to add comment