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() }); }