From bc0257a8c09514af4ecfc228da6aefca442f0050 Mon Sep 17 00:00:00 2001 From: kgpyo Date: Tue, 10 Dec 2019 00:48:47 +0900 Subject: [PATCH] fix: es keyword search query error correction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 기존 keyword 검색 시 오류가 발생하여, term을 must 속성(배열)원소 로 이동 --- apis/product/routes/controller/getProductInfo.js | 7 ------- apis/product/routes/middleware/listView.js | 7 ++++--- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/apis/product/routes/controller/getProductInfo.js b/apis/product/routes/controller/getProductInfo.js index 8c47a6c..0cfbc71 100644 --- a/apis/product/routes/controller/getProductInfo.js +++ b/apis/product/routes/controller/getProductInfo.js @@ -9,13 +9,6 @@ const getProductListController = async (req, res, next) => { }; delete res.locals.filter; } - if (res.locals.keyword) { - res.locals.query = { - ...res.locals.query, - ...res.locals.keyword, - }; - delete res.locals.keyword; - } try { const list = await getElasticSearchResults(res.locals); res.json(list); diff --git a/apis/product/routes/middleware/listView.js b/apis/product/routes/middleware/listView.js index e2f544b..fa61b08 100644 --- a/apis/product/routes/middleware/listView.js +++ b/apis/product/routes/middleware/listView.js @@ -6,7 +6,7 @@ import { } from '../../core/string-conveter'; const addFilter = (filter = [], query) => { - if ('range' in query) { + if ('range' in query || 'term' in query) { return [...filter, query]; } return [...filter, { bool: query }]; @@ -106,12 +106,13 @@ const addOrderToOption = ({ query: { sort } }, res, next) => { next(); }; -// TODO 키워드 검색(토크나이저...) +// TODO 키워드 검색 const addKeywordTofilter = ({ query: { keyword } }, res, next) => { if (keyword) { - res.locals.keyword = { + const query = { term: { title: keyword }, }; + res.locals.filter = addFilter(res.locals.filter, query); } next(); };