From d1df5c9ceba864fcdf8fad6a67a6bf8a55ad6e9b Mon Sep 17 00:00:00 2001 From: Sungwoo Kim Date: Fri, 9 Aug 2024 22:25:49 -0400 Subject: [PATCH] remove heavy query /.*a.*/ takes 1.23 sec. Apply regex if word is longer --- api.cspapers.org/db/bleve/bleve.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api.cspapers.org/db/bleve/bleve.go b/api.cspapers.org/db/bleve/bleve.go index 647d656073..8ce64c1f24 100644 --- a/api.cspapers.org/db/bleve/bleve.go +++ b/api.cspapers.org/db/bleve/bleve.go @@ -88,7 +88,7 @@ func search(req *types.SearchRequest) *types.SearchResponse { keywordQuery := []query.Query{} req.Query = strings.TrimSpace(req.Query) keywordQuery = append(keywordQuery, bleve.NewFuzzyQuery(req.Query)) - if isWord(req.Query) { + if isWord(req.Query) && 3 < len(req.Query) { qs := fmt.Sprintf("/.*%v.*/", req.Query) keywordQuery = append(keywordQuery, bleve.NewQueryStringQuery(qs)) } else { @@ -162,7 +162,7 @@ func search(req *types.SearchRequest) *types.SearchResponse { func batchInsert() { batch := index.NewBatch() - batchSize := 10000 + batchSize := 1000 for i := 0; true; i++ { req, more := <-reqChan