From 3360c46b79690fade94f28573a5f58320d1937af Mon Sep 17 00:00:00 2001 From: zouap Date: Fri, 7 Jan 2022 16:30:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/dbsql/issue_foreigntable_for_es.sql | 5 +++-- routers/search.go | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/models/dbsql/issue_foreigntable_for_es.sql b/models/dbsql/issue_foreigntable_for_es.sql index 786e7c989..bb5c1634e 100644 --- a/models/dbsql/issue_foreigntable_for_es.sql +++ b/models/dbsql/issue_foreigntable_for_es.sql @@ -57,7 +57,7 @@ INSERT INTO public.issue_es( closed_unix, is_locked, amount, - is_transformed,comment) + is_transformed,comment,pr_id) SELECT b.id, b.repo_id, @@ -80,7 +80,8 @@ INSERT INTO public.issue_es( b.is_locked, b.amount, b.is_transformed, - (select array_to_string(array_agg(content order by created_unix desc),',') from public.comment a where a.issue_id=b.id) + (select array_to_string(array_agg(content order by created_unix desc),',') from public.comment a where a.issue_id=b.id), + (select id from public.pull_request d where b.id=d.issue_id and b.is_pull=true) FROM public.issue b,public.repository c where b.repo_id=c.id and c.is_private=false; diff --git a/routers/search.go b/routers/search.go index d966f243c..d0c8013b1 100644 --- a/routers/search.go +++ b/routers/search.go @@ -123,8 +123,10 @@ func searchRepo(ctx *context.Context, TableName string, Key string, Page int, Pa descriptionQuery := elastic.NewMatchQuery("description", Key).Boost(1.5).QueryName("f_second") topicsQuery := elastic.NewMatchQuery("topics", Key).Boost(1).QueryName("f_third") boolQ.Should(nameQuery, descriptionQuery, topicsQuery) - res, err := client.Search(TableName).Query(boolQ).SortBy(elastic.NewScoreSort(), elastic.NewFieldSort(SortBy).Order(ascending)).From((Page - 1) * PageSize).Size(PageSize).Do(ctx.Req.Context()) + res, err := client.Search(TableName).Query(boolQ).SortBy(elastic.NewScoreSort(), elastic.NewFieldSort(SortBy).Order(ascending)).From((Page - 1) * PageSize).Size(PageSize).Highlight(queryHighlight("name", "description", "topics")).Do(ctx.Req.Context()) if err == nil { + searchJson, _ := json.Marshal(res) + log.Info("searchJson=" + string(searchJson)) result := makeRepoResult(res, Key) ctx.JSON(200, result) } else { @@ -134,7 +136,7 @@ func searchRepo(ctx *context.Context, TableName string, Key string, Page int, Pa } else { log.Info("query all content.") //搜索的属性要指定{"timestamp":{"unmapped_type":"date"}} - res, err := client.Search(TableName).SortBy(elastic.NewFieldSort(SortBy).Order(ascending)).From((Page - 1) * PageSize).Size(PageSize).Highlight(queryHighlight("name", "description", "topics")).Do(ctx.Req.Context()) + res, err := client.Search(TableName).SortBy(elastic.NewFieldSort(SortBy).Order(ascending)).From((Page - 1) * PageSize).Size(PageSize).Do(ctx.Req.Context()) if err == nil { searchJson, _ := json.Marshal(res) log.Info("searchJson=" + string(searchJson))