From a79b9a8e42b7cad7eee5159012e6e606922e98a6 Mon Sep 17 00:00:00 2001 From: kgpyo Date: Tue, 17 Dec 2019 20:16:28 +0900 Subject: [PATCH] fix: edit keyword search responses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - es 검색결과 내용 출력하게 반환값 수정(hits.this) - product.static에서 esSearch속성을 조회하기 위해 bind 제거 --- apis/product/db/model/product.js | 12 ++++++++---- apis/product/routes/controller/info.js | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/apis/product/db/model/product.js b/apis/product/db/model/product.js index a933965..9a2b23e 100644 --- a/apis/product/db/model/product.js +++ b/apis/product/db/model/product.js @@ -137,7 +137,7 @@ const productSchema = new Schema({ productSchema.plugin(mongoosastic, mongoosasticSettings); -productSchema.static('search', promiseSearch.bind(productSchema)); +productSchema.static('search', promiseSearch); const pushKeywordForTokenization = (doc) => { documentsToAnalyze.title = [...documentsToAnalyze.title, doc.title]; @@ -191,8 +191,8 @@ Product.createMapping({ }, () => { }); const timer = setInterval(() => { - const title = documentsToAnalyze.title.join(' '); - documentsToAnalyze.title = []; + const title = documentsToAnalyze.title.slice(0, 100).join(' '); + documentsToAnalyze.title = documentsToAnalyze.title.slice(100); if (!title.length) { if (process.env.NODE_ENV === 'development') { clearInterval(timer); @@ -201,6 +201,9 @@ const timer = setInterval(() => { return; } const insertKeyword = (err, { tokens }) => { + if (err) { + return; + } const words = tokens .filter(({ token }) => token.length >= 2) .map(({ token }) => ({ word: token })); @@ -211,9 +214,10 @@ const timer = setInterval(() => { }); }; Product.esClient.indices.analyze({ + index: 'products', body: { text: title, - analyzer: 'nori', + analyzer: 'korean', }, }, insertKeyword); }, KEYWORD_ANALYSIS_CYCLE); diff --git a/apis/product/routes/controller/info.js b/apis/product/routes/controller/info.js index a6ddf65..67a1043 100644 --- a/apis/product/routes/controller/info.js +++ b/apis/product/routes/controller/info.js @@ -11,7 +11,7 @@ export default { ) => { try { const list = await getRecommandKeyword(keyword, fuzzy); - res.json(list); + res.json(list.hits.hits); } catch (e) { next({ status: 500, message: e.toString() }); }