|
|
@@ -100,7 +100,8 @@ SearchClient.prototype.prepareBodyForUpdate = function(body, page) {
|
|
|
bookmark_count: 0, // todo
|
|
|
like_count: page.liker.length || 0,
|
|
|
updated_at: page.updatedAt,
|
|
|
- }
|
|
|
+ },
|
|
|
+ doc_as_upsert: true,
|
|
|
};
|
|
|
|
|
|
body.push(command);
|
|
|
@@ -135,6 +136,23 @@ SearchClient.prototype.prepareBodyForCreate = function(body, page) {
|
|
|
body.push(document);
|
|
|
};
|
|
|
|
|
|
+SearchClient.prototype.prepareBodyForDelete = function(body, page) {
|
|
|
+ if (!Array.isArray(body)) {
|
|
|
+ throw new Error('Body must be an array.');
|
|
|
+ }
|
|
|
+
|
|
|
+ var command = {
|
|
|
+ delete: {
|
|
|
+ _index: this.index_name,
|
|
|
+ _type: 'pages',
|
|
|
+ _id: page._id.toString(),
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ body.push(command);
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
SearchClient.prototype.addPages = function(pages)
|
|
|
{
|
|
|
var self = this;
|
|
|
@@ -165,6 +183,21 @@ SearchClient.prototype.updatePages = function(pages)
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+SearchClient.prototype.deletePages = function(pages)
|
|
|
+{
|
|
|
+ var self = this;
|
|
|
+ var body = [];
|
|
|
+
|
|
|
+ pages.map(function(page) {
|
|
|
+ self.prepareBodyForDelete(body, page);
|
|
|
+ });
|
|
|
+
|
|
|
+ debug('deletePages(): Sending Request to ES', body);
|
|
|
+ return this.client.bulk({
|
|
|
+ body: body,
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
SearchClient.prototype.addAllPages = function()
|
|
|
{
|
|
|
var self = this;
|
|
|
@@ -357,6 +390,8 @@ SearchClient.prototype.searchKeywordUnderPath = function(keyword, path, option)
|
|
|
|
|
|
SearchClient.prototype.syncPageCreated = function(page, user)
|
|
|
{
|
|
|
+ debug('SearchClient.syncPageCreated', page);
|
|
|
+
|
|
|
if (!this.shouldIndexed(page)) {
|
|
|
return ;
|
|
|
}
|
|
|
@@ -372,8 +407,17 @@ SearchClient.prototype.syncPageCreated = function(page, user)
|
|
|
|
|
|
SearchClient.prototype.syncPageUpdated = function(page, user)
|
|
|
{
|
|
|
+ debug('SearchClient.syncPageUpdated', page);
|
|
|
// TODO delete
|
|
|
if (!this.shouldIndexed(page)) {
|
|
|
+ this.deletePages([page])
|
|
|
+ .then(function(res) {
|
|
|
+ debug('deletePages: ES Response', res);
|
|
|
+ })
|
|
|
+ .catch(function(err){
|
|
|
+ debug('deletePages:ES Error', err);
|
|
|
+ });
|
|
|
+
|
|
|
return ;
|
|
|
}
|
|
|
|