Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
pull/1788/head
zouap 3 years ago
parent
commit
3360c46b79
2 changed files with 7 additions and 4 deletions
  1. +3
    -2
      models/dbsql/issue_foreigntable_for_es.sql
  2. +4
    -2
      routers/search.go

+ 3
- 2
models/dbsql/issue_foreigntable_for_es.sql View File

@@ -57,7 +57,7 @@ INSERT INTO public.issue_es(
closed_unix, closed_unix,
is_locked, is_locked,
amount, amount,
is_transformed,comment)
is_transformed,comment,pr_id)
SELECT SELECT
b.id, b.id,
b.repo_id, b.repo_id,
@@ -80,7 +80,8 @@ INSERT INTO public.issue_es(
b.is_locked, b.is_locked,
b.amount, b.amount,
b.is_transformed, 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; FROM public.issue b,public.repository c where b.repo_id=c.id and c.is_private=false;






+ 4
- 2
routers/search.go View File

@@ -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") descriptionQuery := elastic.NewMatchQuery("description", Key).Boost(1.5).QueryName("f_second")
topicsQuery := elastic.NewMatchQuery("topics", Key).Boost(1).QueryName("f_third") topicsQuery := elastic.NewMatchQuery("topics", Key).Boost(1).QueryName("f_third")
boolQ.Should(nameQuery, descriptionQuery, topicsQuery) 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 { if err == nil {
searchJson, _ := json.Marshal(res)
log.Info("searchJson=" + string(searchJson))
result := makeRepoResult(res, Key) result := makeRepoResult(res, Key)
ctx.JSON(200, result) ctx.JSON(200, result)
} else { } else {
@@ -134,7 +136,7 @@ func searchRepo(ctx *context.Context, TableName string, Key string, Page int, Pa
} else { } else {
log.Info("query all content.") log.Info("query all content.")
//搜索的属性要指定{"timestamp":{"unmapped_type":"date"}} //搜索的属性要指定{"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 { if err == nil {
searchJson, _ := json.Marshal(res) searchJson, _ := json.Marshal(res)
log.Info("searchJson=" + string(searchJson)) log.Info("searchJson=" + string(searchJson))


Loading…
Cancel
Save