Skip to content

Commit

Permalink
fix: edit keyword search responses
Browse files Browse the repository at this point in the history
- es ๊ฒ€์ƒ‰๊ฒฐ๊ณผ ๋‚ด์šฉ ์ถœ๋ ฅํ•˜๊ฒŒ ๋ฐ˜ํ™˜๊ฐ’ ์ˆ˜์ •(hits.this)
  • Loading branch information
kgpyo committed Dec 17, 2019
1 parent 8036179 commit 8b20bb6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions apis/product/db/model/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 }));
Expand All @@ -211,9 +214,10 @@ const timer = setInterval(() => {
});
};
Product.esClient.indices.analyze({
index: 'products',
body: {
text: title,
analyzer: 'nori',
analyzer: 'korean',
},
}, insertKeyword);
}, KEYWORD_ANALYSIS_CYCLE);
Expand Down
2 changes: 1 addition & 1 deletion apis/product/routes/controller/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() });
}
Expand Down

0 comments on commit 8b20bb6

Please sign in to comment.