Guest User

Untitled

a guest
Nov 23rd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. var IndexTankCollection = IndexTankService.extend({
  2.  
  3. /**
  4. */
  5.  
  6. 'override __construct': function(config, name)
  7. {
  8. this._super(config);
  9.  
  10. this.name = name;
  11.  
  12. this._insertBatch = [];
  13. this._lazyInsertCallback = lazyCallback(this.getMethod('_insertDocBatch'), 500)
  14. },
  15.  
  16. /**
  17. * adds to the collection
  18. */
  19.  
  20. 'create': function(callback)
  21. {
  22. this._put(this._getIndexUrl(), callback);
  23. },
  24.  
  25. /**
  26. * removes the collection
  27. */
  28.  
  29. 'remove': function(callback)
  30. {
  31. this._delete(this._getIndexUrl(), callback);
  32. },
  33.  
  34. /**
  35. * returns the metadata of given collection
  36. */
  37.  
  38. 'getMetadata': function(callback)
  39. {
  40. this._get(this._getIndexUrl(), callback);
  41. },
  42.  
  43. /**
  44. * adds a document to the index
  45. * @ops
  46. * - @docid the document identifier
  47. * - @fields a map from field name to field value
  48. * - @variables a map of the var number to float
  49. * - @categories a map from the category name to its value
  50. */
  51.  
  52. 'addDoc': function(ops, callback)
  53. {
  54. if(ops.fields._id)
  55. {
  56. ops.docid = ops.fields._id.toString();
  57. delete ops.fields._id;
  58. }
  59.  
  60.  
  61. //send batch collections
  62. this._insertBatch.push(ops);
  63.  
  64. //start the insertion process
  65. this._lazyInsertCallback();
  66. },
  67.  
  68. /**
  69. * removes a doc
  70. */
  71.  
  72. 'removeDoc': function(docid, callback)
  73. {
  74. this._delete(this._getIndexUrl() + '/docs', JSON.stringify({ docid: docid }), callback);
  75. },
  76.  
  77. /**
  78. * searches for a document
  79. * @ops
  80. * - @q the query string
  81. * - @len the number of items to return
  82. * - @function the the number of scoring function to use
  83. * - @fetch comma-separated list of fields to fetch. * returns all
  84. * - @snippet comma-separated list of fields to snippet
  85. * - @var<n> value of query variable
  86. * - @category_filters json map of categoriy name
  87. * - @filter_docvar comma-separated list of ranges to filter
  88. * - @filter_function comma-separated list of ranges to filter the values of functions.
  89. */
  90.  
  91. 'search': function(ops, callback)
  92. {
  93. this._get(this._getIndexUrl() + '/search', ops, callback);
  94. },
  95.  
  96. /**
  97. * promotes item to the top of the query's result page
  98. */
  99.  
  100. 'promote': function(docid, query)
  101. {
  102. this._put(this._getIndexUrl() + '/promote', { docid: docid, query: query }, function()
  103. {
  104.  
  105. });
  106. },
  107.  
  108. /**
  109. */
  110.  
  111. 'autoComplete': function(query, callbackString, callback)
  112. {
  113. this._get(this._getIndexUrl() + '/autocomplete', {query: query, callback: callbackString }, callback);
  114. },
  115.  
  116. /**
  117. * inserts a batch of documents
  118. */
  119.  
  120. '_insertDocBatch': function()
  121. {
  122. var batch = this._insertBatch;
  123. this._insertBatch = [];
  124.  
  125. this._put(this._getIndexUrl() + '/docs', JSON.stringify(batch), function()
  126. {
  127. console.log("INSERTED")
  128. });
  129. },
  130.  
  131. /**
  132. * returns the index url
  133. */
  134.  
  135. '_getIndexUrl': function()
  136. {
  137. return '/indexes/' + this.name;
  138. }
  139. });
Add Comment
Please, Sign In to add comment