UNPKG

owhat-job

Version:

owhat红包清理

1,303 lines (1,157 loc) 48.6 kB
'use strict'; var _regenerator = require('babel-runtime/regenerator'); var _regenerator2 = _interopRequireDefault(_regenerator); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } require('array.prototype.flatmap').shim(); // const config = require("config"); // console.log(config); // const esConfig = config.get('EsConnect.dbConfig'); var _require = require('@elastic/elasticsearch'), Client = _require.Client; var client = new Client({ node: "http://172.17.102.128:9200" //esConfig.url }); var articleIndexName = "law-article", topicIndexName = "law-topic"; /******* * 文章映射 * **** */ var articleMapping = { properties: { id: { type: 'keyword' }, name: { type: 'text', analyzer: 'ik_max_word', "search_analyzer": "ik_smart", "fields": { "full_pinyin": { //全拼分词 "type": "completion", "analyzer": "full_pinyin_analyzer", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 }, "prefix_pinyin": { //拼音首字母分词 "type": "completion", "analyzer": "prefix_pinyin_analyzer", "search_analyzer": "standard", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 }, "standardText": { //单字分词 "type": "completion", "analyzer": "standard", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 } } }, authorID: { type: 'keyword' }, authorName: { type: 'keyword' }, coverImage: { type: 'keyword' }, topicID: { type: 'keyword' }, firstCategory: { type: 'nested', properties: { categoryID: { type: 'integer' }, categoryName: { type: 'text', analyzer: 'ik_max_word', "search_analyzer": "ik_smart", "fields": { "full_pinyin": { //全拼分词 "type": "completion", "analyzer": "full_pinyin_analyzer", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 }, "prefix_pinyin": { //拼音首字母分词 "type": "completion", "analyzer": "prefix_pinyin_analyzer", "search_analyzer": "standard", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 }, "standardText": { //单字分词 "type": "completion", "analyzer": "standard", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 } } } } }, secondCategory: { type: 'nested', properties: { categoryID: { type: 'integer' }, categoryName: { type: 'text', analyzer: 'ik_max_word', "search_analyzer": "ik_smart", "fields": { "full_pinyin": { //全拼分词 "type": "completion", "analyzer": "full_pinyin_analyzer", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 }, "prefix_pinyin": { //拼音首字母分词 "type": "completion", "analyzer": "prefix_pinyin_analyzer", "search_analyzer": "standard", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 }, "standardText": { //单字分词 "type": "completion", "analyzer": "standard", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 } } } } }, intro: { type: 'text', analyzer: 'ik_max_word', "search_analyzer": "ik_smart", "fields": { "full_pinyin": { //全拼分词 "type": "completion", "analyzer": "full_pinyin_analyzer", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 }, "prefix_pinyin": { //拼音首字母分词 "type": "completion", "analyzer": "prefix_pinyin_analyzer", "search_analyzer": "standard", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 }, "standardText": { //单字分词 "type": "completion", "analyzer": "standard", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 } } }, content: { type: 'text', analyzer: 'ik_max_word', "search_analyzer": "ik_smart", "fields": { "full_pinyin": { //全拼分词 "type": "completion", "analyzer": "full_pinyin_analyzer", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 }, "prefix_pinyin": { //拼音首字母分词 "type": "completion", "analyzer": "prefix_pinyin_analyzer", "search_analyzer": "standard", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 }, "standardText": { //单字分词 "type": "completion", "analyzer": "standard", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 } } }, keyWords: { type: 'keyword' // , // "fields": { // "keyword": { // "type": "keyword", // "ignore_above": 2048 // } // } }, source: { type: 'keyword' }, sourceurl: { type: 'keyword' }, isTopic: { type: 'integer' }, isTop: { type: 'integer' }, isHomeTop: { type: 'integer' }, isExcel: { type: 'integer' }, canComment: { type: 'integer' }, allowComment: { type: 'integer' }, commentCount: { type: 'integer' }, viewCount: { type: 'integer' }, createTime: { type: 'date' // , // format: "YYYY-MM-DD HH:mm:ss" // , // "full_pinyin": { //全拼分词 // "type": "completion", // "analyzer": "full_pinyin_analyzer", // // "payloads": true, // "preserve_separators": false, // "preserve_position_increments": true, // "max_input_length": 50 // }, // "prefix_pinyin": { //拼音首字母分词 // "type": "completion", // "analyzer": "prefix_pinyin_analyzer", // "search_analyzer": "standard", // // "payloads": true, // "preserve_separators": false, // "preserve_position_increments": true, // "max_input_length": 50 // }, // "suggestText": { //单字分词 // "type": "completion", // "analyzer": "standard", // // "payloads": true, // "preserve_separators": false, // "preserve_position_increments": true, // "max_input_length": 50 // } } } }; var setting = { "analysis": { "filter": { // "_pattern": { // "type": "pattern_capture", // "preserve_original": "true", // "patterns": ["([0-9])", "([a-z])"] // }, "full_pinyin": { "keep_first_letter": "false", "keep_none_chinese_in_first_letter": "false", "type": "pinyin", "keep_original": "false", "keep_full_pinyin": "true" }, "prefix_pinyin": { "keep_first_letter": "true", "none_chinese_pinyin_tokenize": "false", "type": "pinyin", "keep_original": "false", "keep_full_pinyin": "false" }, "ik_pinyin": { "type": "pinyin", "keep_separate_first_letter": true, "keep_full_pinyin": true, "keep_original": true, "limit_first_letter_length": 16, "lowercase": true, "remove_duplicated_term": true } }, "analyzer": { "full_pinyin_analyzer": { "filter": ["lowercase", "full_pinyin"], "tokenizer": "standard" }, "prefix_pinyin_analyzer": { "filter": ["lowercase", "prefix_pinyin"], "tokenizer": "standard" }, "ik_smart_pinyin": { "type": "custom", "tokenizer": "ik_smart", "filter": ["ik_pinyin", "word_delimiter"] }, "ik_max_word_pinyin": { "type": "custom", "tokenizer": "ik_max_word", "filter": ["ik_pinyin", "word_delimiter"] } } } /******* * 课题映射 * **** */ };var topicMapping = { properties: { id: { type: 'keyword' }, name: { type: 'text', analyzer: 'ik_max_word', "search_analyzer": "ik_smart", "fields": { "full_pinyin": { //全拼分词 "type": "completion", "analyzer": "full_pinyin_analyzer", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 }, "prefix_pinyin": { //拼音首字母分词 "type": "completion", "analyzer": "prefix_pinyin_analyzer", "search_analyzer": "standard", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 }, "standardText": { //单字分词 "type": "completion", "analyzer": "standard", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 } } }, firstCategory: { type: 'nested', properties: { categoryID: { type: 'integer' }, categoryName: { type: 'text', analyzer: 'ik_max_word', "search_analyzer": "ik_smart", "fields": { "full_pinyin": { //全拼分词 "type": "completion", "analyzer": "full_pinyin_analyzer", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 }, "prefix_pinyin": { //拼音首字母分词 "type": "completion", "analyzer": "prefix_pinyin_analyzer", "search_analyzer": "standard", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 }, "standardText": { //单字分词 "type": "completion", "analyzer": "standard", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 } } } } }, secondCategory: { type: 'nested', properties: { categoryID: { type: 'integer' }, categoryName: { type: 'text', analyzer: 'ik_max_word', "search_analyzer": "ik_smart", "fields": { "full_pinyin": { //全拼分词 "type": "completion", "analyzer": "full_pinyin_analyzer", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 }, "prefix_pinyin": { //拼音首字母分词 "type": "completion", "analyzer": "prefix_pinyin_analyzer", "search_analyzer": "standard", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 }, "standardText": { //单字分词 "type": "completion", "analyzer": "standard", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 } } } } }, intro: { type: 'text', analyzer: 'ik_max_word', "search_analyzer": "ik_smart", "fields": { "full_pinyin": { //全拼分词 "type": "completion", "analyzer": "full_pinyin_analyzer", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 }, "prefix_pinyin": { //拼音首字母分词 "type": "completion", "analyzer": "prefix_pinyin_analyzer", "search_analyzer": "standard", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 }, "standardText": { //单字分词 "type": "completion", "analyzer": "standard", // "payloads": true, "preserve_separators": false, "preserve_position_increments": true, "max_input_length": 50 } } }, authorID: { type: 'keyword' }, articleID: { type: 'keyword' }, creater: { type: 'keyword' }, // creater: { // type: 'text', // analyzer: 'ik_max_word', // "search_analyzer": "ik_smart", // fields: { // keyword: { // type: "keyword", // ignore_above: 256 // } // } // }, createTime: { type: 'date' }, delFlag: { type: 'integer' } } /******* * 检查数据的索引是否准确 * **** */ };var indices = function indices() { return esClient.cat.indices({ v: true }).then(console.log).catch(function (err) { return console.error('Error connecting to the es client: ' + err); }); }; var existsByID = function () { var _ref = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee(index, id) { var _ref2, body; return _regenerator2.default.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; return client.exists({ index: index, id: id }); case 2: _ref2 = _context.sent; body = _ref2.body; console.log(body); // true return _context.abrupt('return', body); case 6: case 'end': return _context.stop(); } } }, _callee, undefined); })); return function existsByID(_x, _x2) { return _ref.apply(this, arguments); }; }(); /******* * 判断索引是否存在 * **** */ //index string | string[] var exists = function () { var _ref3 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee2(index) { var _ref4, body; return _regenerator2.default.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _context2.next = 2; return client.indices.exists({ index: index }); case 2: _ref4 = _context2.sent; body = _ref4.body; return _context2.abrupt('return', body); case 5: case 'end': return _context2.stop(); } } }, _callee2, undefined); })); return function exists(_x3) { return _ref3.apply(this, arguments); }; }(); /******* * 创建索引(同时mapping) * **** */ var createIndex = function () { var _ref5 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee3(indexName) { var mappings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var settings = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var _ref6, body; return _regenerator2.default.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: _context3.next = 2; return client.indices.create({ index: indexName, body: { mappings: mappings, settings: settings } }, { ignore: [400] }); case 2: _ref6 = _context3.sent; body = _ref6.body; return _context3.abrupt('return', body); case 5: case 'end': return _context3.stop(); } } }, _callee3, undefined); })); return function createIndex(_x6) { return _ref5.apply(this, arguments); }; }(); // createIndex(articleIndexName, articleMapping, setting).then(item => { // console.log(item); // }); // createIndex(topicIndexName, topicMapping, setting).then(item => { // console.log(item); // }); // exists(["tweets"]).then(item => { // console.log(item); // }) // existsByID("tweets", 1).catch(console.log).then(v => { // console.log("vvvvvvvvvvvv" + v); // }); /******* * 批量操作 * **** */ var bulk_law = function () { var _ref7 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee4(indexName, data) { var body, _ref8, bulkResponse; return _regenerator2.default.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: body = data.flatMap(function (doc) { return [{ index: { _index: indexName, _id: doc.id } }, doc]; }); // console.log(body); _context4.next = 3; return client.bulk({ refresh: true, body: body }); case 3: _ref8 = _context4.sent; bulkResponse = _ref8.body; if (bulkResponse.errors) { console.log(bulkResponse); process.exit(1); } case 6: case 'end': return _context4.stop(); } } }, _callee4, this); })); return function bulk_law(_x7, _x8) { return _ref7.apply(this, arguments); }; }(); /******* * 批量添加文章 * **** */ exports.bulkArticle = function () { var _ref9 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee5(data) { return _regenerator2.default.wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: _context5.next = 2; return bulk_law(articleIndexName, data); case 2: case 'end': return _context5.stop(); } } }, _callee5, this); })); return function (_x9) { return _ref9.apply(this, arguments); }; }(); // exports.bulkArticle(); /******* * 批量添加课题 * **** */ exports.bulkTopic = function () { var _ref10 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee6(data) { var dataset; return _regenerator2.default.wrap(function _callee6$(_context6) { while (1) { switch (_context6.prev = _context6.next) { case 0: dataset = [{ id: '314124cdcbfa11e9a66300163e308174', name: '测试进行中课题', firstCategory: { categoryID: 1, categoryName: '互联网金融' }, secondCategory: { categoryID: 2, categoryName: '银行' }, intro: 'dddddddddddddddd', creater: '0ced5fefcbfa11e9a66300163e308174', createTime: new Date('2019/9/16 15:03:30'), delFlag: 3 }, { id: 'd5dd6691cbf911e9a66300163e308174', name: '课题1', firstCategory: { categoryID: 12, categoryName: '电子商务与社交' }, secondCategory: { categoryID: 13, categoryName: '购物' }, authorID: '6cbb1c41cbf611e9a66300163e308174', articleID: '1ecab369caee11e9a66300163e308174', intro: '课题1介绍', creater: '0ced5fefcbfa11e9a66300163e308174', createTime: new Date('2019/9/16 15:03:30'), delFlag: 3 }]; _context6.next = 3; return bulk_law(topicIndexName, dataset); case 3: case 'end': return _context6.stop(); } } }, _callee6, this); })); return function (_x10) { return _ref10.apply(this, arguments); }; }(); // exports.bulkTopic(); /******* * 获取文章列表 * **** */ exports.getArticles = function () { var _ref11 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee7(searchStr) { var pageSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10; var pageIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; var searchAfterPros = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : []; var itemIndex, query, _ref12, body, hits, total, items, returnObj; return _regenerator2.default.wrap(function _callee7$(_context7) { while (1) { switch (_context7.prev = _context7.next) { case 0: // const deepCount = 10000; // const deepPage = deepCount % pageSize == 0 ? deepCount / pageSize : deepCount / pageSize + 1; // //true 深分页 false 浅分页 // const sType = pageIndex > deepPage; //pageIndex * pageSize > 10; itemIndex = (pageIndex - 1) * pageSize; query = {}; if (!searchStr || searchStr === "") { query["match_all"] = {}; } else { query["bool"] = { should: [{ nested: { path: ["firstCategory"], query: { bool: { must: [{ match: { "firstCategory.categoryName": searchStr } }] } } } }, { nested: { path: ["secondCategory"], query: { bool: { must: [{ match: { "secondCategory.categoryName": searchStr } }] } } } }, { multi_match: { query: searchStr, type: "best_fields", //完全匹配的文档占的评分比较高,则需要使用best_fields fields: ["name", "name.full_pinyin", "name.prefix_pinyin", "name.standardText", "content", "content.full_pinyin", "content.prefix_pinyin", "content.standardText"], tie_breaker: 0.3 } }] }; } _context7.next = 5; return client.search({ index: articleIndexName, body: { query: query, from: itemIndex, size: pageSize, highlight: { number_of_fragments: 1, //返回结果最多可以包含几段不连续的文字 fragment_size: 10, //一段fragment 包含多少个字符 // no_match_size: 2, //即使字段中没有关键字命中,也可以返回一段文字,该参数表示从0-2索引字符返回 fields: { "content": { // number_of_fragments: 0, //返回结果最多可以包含几段不连续的文字 // fragment_size: 10, //一段fragment 包含多少个字符 "pre_tags": ['<i class="ic">'], "post_tags": ['</i>'], "no_match_size": 1 }, "name": { "pre_tags": ["<em>"], "post_tags": ["</em>"], "no_match_size": 1 } } }, sort: [{ "isHomeTop": "desc" }, { "isTop": "desc" }, { "createTime": "desc" }] } }); case 5: _ref12 = _context7.sent; body = _ref12.body; hits = body.hits; // console.log(hits) total = hits.total.value; // console.log(hits.hits); items = hits.hits.map(function (item) { var obj = Object.assign({}, item._source); obj["ID"] = obj.id; obj["highlight"] = item.highlight; delete obj.id; return obj; }); returnObj = { "total": total, "items": items, "searchAfterPros": [] }; console.log(returnObj); return _context7.abrupt('return', returnObj); case 13: case 'end': return _context7.stop(); } } }, _callee7, undefined); })); return function (_x14) { return _ref11.apply(this, arguments); }; }(); // exports.getArticles("222333", 10, 1) /******* * 根据文章ID删除文章 * **** */ exports.delArticleByID = function () { var _ref13 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee8(articleID) { var res; return _regenerator2.default.wrap(function _callee8$(_context8) { while (1) { switch (_context8.prev = _context8.next) { case 0: _context8.next = 2; return client.delete({ id: articleID, index: articleIndexName, refresh: true }).catch(function (error) { console.log(error.meta.body); }); case 2: res = _context8.sent; if (res) { console.log("======文章搜索引擎下架成功======" + res); } case 4: case 'end': return _context8.stop(); } } }, _callee8, undefined); })); return function (_x15) { return _ref13.apply(this, arguments); }; }(); // exports.delArticleByID('16b750f3f7ac48ec810b9a7cf6bb4832') //获取课题列表 exports.getTopics = function () { var _ref14 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee9(searchStr) { var pageSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10; var pageIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; var searchAfterPros = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : []; var itemIndex, query, _ref15, body, hits, total, items, returnObj; return _regenerator2.default.wrap(function _callee9$(_context9) { while (1) { switch (_context9.prev = _context9.next) { case 0: // const deepCount = 10000; // const deepPage = deepCount % pageSize == 0 ? deepCount / pageSize : deepCount / pageSize + 1; // //true 深分页 false 浅分页 // const sType = pageIndex > deepPage; //pageIndex * pageSize > 10; itemIndex = (pageIndex - 1) * pageSize; query = {}; if (!searchStr || searchStr === "") { query["match_all"] = {}; } else { query["bool"] = { should: [{ nested: { path: ["firstCategory"], query: { bool: { must: [{ match: { "firstCategory.categoryName": searchStr } }] } } } }, { nested: { path: ["secondCategory"], query: { bool: { must: [{ match: { "secondCategory.categoryName": searchStr } }] } } } }, { multi_match: { query: searchStr, type: "best_fields", //完全匹配的文档占的评分比较高,则需要使用best_fields fields: ["name", "name.full_pinyin", "name.prefix_pinyin", "name.standardText", "intro", "intro.full_pinyin", "intro.prefix_pinyin", "intro.standardText"], tie_breaker: 0.3 } }] // query["multi_match"] = { // query: searchStr, // type: "best_fields", //完全匹配的文档占的评分比较高,则需要使用best_fields // fields: ["name", "content"], // tie_breaker: 0.3 // }; }; } _context9.next = 5; return client.search({ index: topicIndexName, body: { query: query, from: itemIndex, size: pageSize, highlight: { fields: { "intro": { // number_of_fragments: 0, //返回结果最多可以包含几段不连续的文字 // fragment_size: 10, //一段fragment 包含多少个字符 "pre_tags": ["<em>"], "post_tags": ["</em>"] }, "name": { "pre_tags": ["em"], "post_tags": ["</em>"] } } }, sort: [{ "createTime": "desc" }] } }); case 5: _ref15 = _context9.sent; body = _ref15.body; hits = body.hits; // console.log(hits) total = hits.total.value; // console.log(hits.hits); items = hits.hits.map(function (item) { var obj = Object.assign({}, item._source); obj["ID"] = obj.id; obj["Name"] = obj.name; obj["highlight"] = item.highlight; delete obj.id; delete obj.name; return obj; }); returnObj = { "total": total, "items": items, "searchAfterPros": [] }; console.log(returnObj); return _context9.abrupt('return', returnObj); case 13: case 'end': return _context9.stop(); } } }, _callee9, undefined); })); return function (_x19) { return _ref14.apply(this, arguments); }; }(); // exports.getTopics("课题1"); //“文章”搜索建议 exports.suggestArticle = function () { var _ref16 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee10(searchStr) { var _ref17, body; return _regenerator2.default.wrap(function _callee10$(_context10) { while (1) { switch (_context10.prev = _context10.next) { case 0: _context10.next = 2; return client.search({ index: articleIndexName, body: { // query: { // multi_match: { // query: searchStr, // type: "best_fields", //完全匹配的文档占的评分比较高,则需要使用best_fields // fields: ["name", "content"], // tie_breaker: 0.3 // } // }, suggest: { text: searchStr, // "suggest-keyWords": { // // text: searchStr, // term: { // // "suggest_mode": "missing", // field: 'keyWords.keyword' // } // }, "suggest-content": { // text: searchStr, term: { "suggest_mode": "always", field: 'content', analyzer: 'ik_smart' } } } } }).catch(function (error) { console.log(error.meta.body); }); case 2: _ref17 = _context10.sent; body = _ref17.body; console.log(body.suggest); case 5: case 'end': return _context10.stop(); } } }, _callee10, undefined); })); return function (_x20) { return _ref16.apply(this, arguments); }; }(); // exports.suggestArticle("心"); //相似文章 exports.likeArticles = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee11() { var keyWords = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10; var _ref19, body, hits, total, items, returnObj; return _regenerator2.default.wrap(function _callee11$(_context11) { while (1) { switch (_context11.prev = _context11.next) { case 0: _context11.next = 2; return client.search({ index: articleIndexName, body: { query: { bool: { must: [{ terms: { "keyWords": keyWords } }] } }, from: 0, size: size, sort: [{ "createTime": "desc" }] } }); case 2: _ref19 = _context11.sent; body = _ref19.body; hits = body.hits; // console.log(hits) total = hits.total.value; // console.log(hits.hits); items = hits.hits.map(function (item) { var obj = Object.assign({}, item._source); obj["ID"] = obj.id; obj["highlight"] = item.highlight; delete obj.id; return obj; }); returnObj = { "total": total, "items": items, "searchAfterPros": [] }; console.log(returnObj); return _context11.abrupt('return', returnObj); case 10: case 'end': return _context11.stop(); } } }, _callee11, undefined); })); // exports.likeArticles(['其他']);