Skip to content

Commit

Permalink
fix: edit keyword search responses
Browse files Browse the repository at this point in the history
- es 검색결과 내용 출력하게 반환값 수정(hits.this)
- product.static에서 esSearch속성을 조회하기 위해 bind 제거
  • Loading branch information
kgpyo committed Dec 18, 2019
1 parent 873f3d1 commit a79b9a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions apis/product/db/model/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down 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 a79b9a8

Please sign in to comment.