Signed-off-by: Zhang Yuhang zhangyuhang25@huawei.com --- src/lib/web_backend.rb | 49 ++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 21 deletions(-)
diff --git a/src/lib/web_backend.rb b/src/lib/web_backend.rb index 48cfadb..c8b6b66 100644 --- a/src/lib/web_backend.rb +++ b/src/lib/web_backend.rb @@ -47,7 +47,7 @@ end def filter_tbox_group(es_result) result = Set.new es_result.each do |r| - if r =~ /(^.+--.+$)|(^vm-.*-\d\w*-([a-zA-Z]+)|(\d+)$)/ + if r =~ /(^.+--.+$)|(^vm-.*-\d\w*-(([a-zA-Z]+)|(\d+))$)/ index = r.index('--') || r.rindex('-') r = r[0, index] end @@ -245,26 +245,36 @@ def es_search(must, size, from) } return {}, total if wrong_size?(size, from)
+ p query return es_query(query)['hits']['hits'], total end
-def get_job(result) - job = {} - ALL_FIELDS.each do |f| - job[f] = result[f] +def get_jobs_result(result) + jobs = [] + result.each do |r| + job = {} + ALL_FIELDS.each do |f| + job[f] = r['_source'][f] + end + jobs << job end - job + jobs end
-def search_job(git_repo, page_size, page_num) +def search_job(fields, page_size, page_num) must = [] - must << { regexp: { upstream_repo: ".*#{git_repo}.*" } } if git_repo - jobs = [] - result, total = es_search(must, page_size, page_num * page_size) - result.each do |r| - jobs << get_job(r['_source']) + FIELDS.each do |field| + value = space_to_nil(fields[field]) + next unless value + + must << if field == 'upstream_repo' + { regexp: { field => ".*#{value}.*" } } + else + { term: { field => value } } + end end - return jobs, total + result, total = es_search(must, page_size, page_num * page_size) + return get_jobs_result(result), total end
def get_banner(git_repo, branches) @@ -291,17 +301,14 @@ def get_optimize_jobs_braches(jobs) end
def get_jobs_body(params) - git_repo = space_to_nil(params[:upstream_repo]) - page_size = get_positive_number(params[:page_size], 20) - page_num = get_positive_number(params[:page_num], 1) - 1 - jobs, total = search_job(git_repo, page_size, page_num) + page_size = get_positive_number(params.delete(:page_size), 20) + page_num = get_positive_number(params.delete(:page_num), 1) - 1 + jobs, total = search_job(params, page_size, page_num) jobs, branches = get_optimize_jobs_braches(jobs) { total: total, - filter: { - upstream_repo: git_repo - }, - banner: get_banner(git_repo, branches), + filter: params, + banner: get_banner(params[:upstream_repo], branches), jobs: jobs, fields: FIELDS }.to_json
we'd better give an example of request url
On Mon, Oct 19, 2020 at 06:47:51PM +0800, Zhang Yuhang wrote:
Signed-off-by: Zhang Yuhang zhangyuhang25@huawei.com
src/lib/web_backend.rb | 49 ++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 21 deletions(-)
diff --git a/src/lib/web_backend.rb b/src/lib/web_backend.rb index 48cfadb..c8b6b66 100644 --- a/src/lib/web_backend.rb +++ b/src/lib/web_backend.rb @@ -47,7 +47,7 @@ end def filter_tbox_group(es_result) result = Set.new es_result.each do |r|
- if r =~ /(^.+--.+$)|(^vm-.*-\d\w*-([a-zA-Z]+)|(\d+)$)/
- if r =~ /(^.+--.+$)|(^vm-.*-\d\w*-(([a-zA-Z]+)|(\d+))$)/
why we need filter testbox?
index = r.index('--') || r.rindex('-') r = r[0, index] end
@@ -245,26 +245,36 @@ def es_search(must, size, from) } return {}, total if wrong_size?(size, from)
- p query
remove this line
return es_query(query)['hits']['hits'], total end
-def get_job(result)
- job = {}
- ALL_FIELDS.each do |f|
- job[f] = result[f]
+def get_jobs_result(result)
- jobs = []
- result.each do |r|
- job = {}
- ALL_FIELDS.each do |f|
job[f] = r['_source'][f]
- end
- jobs << job end
- job
- jobs
end
-def search_job(git_repo, page_size, page_num) +def search_job(fields, page_size, page_num)
how about fields => query_field or query_condition
must = []
- must << { regexp: { upstream_repo: ".*#{git_repo}.*" } } if git_repo
- jobs = []
- result, total = es_search(must, page_size, page_num * page_size)
- result.each do |r|
- jobs << get_job(r['_source'])
- FIELDS.each do |field|
where created FIELDS? haven't saw it in this patch
Thanks, Weitao
- value = space_to_nil(fields[field])
- next unless value
- must << if field == 'upstream_repo'
{ regexp: { field => ".*#{value}.*" } }
else
{ term: { field => value } }
endend
- return jobs, total
- result, total = es_search(must, page_size, page_num * page_size)
- return get_jobs_result(result), total
end
def get_banner(git_repo, branches) @@ -291,17 +301,14 @@ def get_optimize_jobs_braches(jobs) end
def get_jobs_body(params)
- git_repo = space_to_nil(params[:upstream_repo])
- page_size = get_positive_number(params[:page_size], 20)
- page_num = get_positive_number(params[:page_num], 1) - 1
- jobs, total = search_job(git_repo, page_size, page_num)
- page_size = get_positive_number(params.delete(:page_size), 20)
- page_num = get_positive_number(params.delete(:page_num), 1) - 1
- jobs, total = search_job(params, page_size, page_num) jobs, branches = get_optimize_jobs_braches(jobs) { total: total,
- filter: {
upstream_repo: git_repo
- },
- banner: get_banner(git_repo, branches),
- filter: params,
- banner: get_banner(params[:upstream_repo], branches), jobs: jobs, fields: FIELDS }.to_json
-- 2.23.0
On Tue, Oct 20, 2020 at 10:53:01AM +0800, Lu Weitao wrote:
we'd better give an example of request url
On Mon, Oct 19, 2020 at 06:47:51PM +0800, Zhang Yuhang wrote:
Signed-off-by: Zhang Yuhang zhangyuhang25@huawei.com
src/lib/web_backend.rb | 49 ++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 21 deletions(-)
diff --git a/src/lib/web_backend.rb b/src/lib/web_backend.rb index 48cfadb..c8b6b66 100644 --- a/src/lib/web_backend.rb +++ b/src/lib/web_backend.rb @@ -47,7 +47,7 @@ end def filter_tbox_group(es_result) result = Set.new es_result.each do |r|
- if r =~ /(^.+--.+$)|(^vm-.*-\d\w*-([a-zA-Z]+)|(\d+)$)/
- if r =~ /(^.+--.+$)|(^vm-.*-\d\w*-(([a-zA-Z]+)|(\d+))$)/
why we need filter testbox?
to show in web in a specified format.
database: "vm-hixx-2p8g--zyh" web: "vm-hixx-2p8g"
index = r.index('--') || r.rindex('-') r = r[0, index] end
@@ -245,26 +245,36 @@ def es_search(must, size, from) } return {}, total if wrong_size?(size, from)
- p query
remove this line
OK, Thanks.
return es_query(query)['hits']['hits'], total end
-def get_job(result)
- job = {}
- ALL_FIELDS.each do |f|
- job[f] = result[f]
+def get_jobs_result(result)
- jobs = []
- result.each do |r|
- job = {}
- ALL_FIELDS.each do |f|
job[f] = r['_source'][f]
- end
- jobs << job end
- job
- jobs
end
-def search_job(git_repo, page_size, page_num) +def search_job(fields, page_size, page_num)
how about fields => query_field or query_condition
query_condition
must = []
- must << { regexp: { upstream_repo: ".*#{git_repo}.*" } } if git_repo
- jobs = []
- result, total = es_search(must, page_size, page_num * page_size)
- result.each do |r|
- jobs << get_job(r['_source'])
- FIELDS.each do |field|
where created FIELDS? haven't saw it in this patch
Thanks, Weitao
It defined in "web_backend.rb" header, not appeared in here.
Thanks, Zhang Yuhang
- value = space_to_nil(fields[field])
- next unless value
- must << if field == 'upstream_repo'
{ regexp: { field => ".*#{value}.*" } }
else
{ term: { field => value } }
endend
- return jobs, total
- result, total = es_search(must, page_size, page_num * page_size)
- return get_jobs_result(result), total
end
def get_banner(git_repo, branches) @@ -291,17 +301,14 @@ def get_optimize_jobs_braches(jobs) end
def get_jobs_body(params)
- git_repo = space_to_nil(params[:upstream_repo])
- page_size = get_positive_number(params[:page_size], 20)
- page_num = get_positive_number(params[:page_num], 1) - 1
- jobs, total = search_job(git_repo, page_size, page_num)
- page_size = get_positive_number(params.delete(:page_size), 20)
- page_num = get_positive_number(params.delete(:page_num), 1) - 1
- jobs, total = search_job(params, page_size, page_num) jobs, branches = get_optimize_jobs_braches(jobs) { total: total,
- filter: {
upstream_repo: git_repo
- },
- banner: get_banner(git_repo, branches),
- filter: params,
- banner: get_banner(params[:upstream_repo], branches), jobs: jobs, fields: FIELDS }.to_json
-- 2.23.0
On Tue, Oct 20, 2020 at 11:13:20AM +0800, Lu Weitao wrote:
- if r =~ /(^.+--.+$)|(^vm-.*-\d\w*-(([a-zA-Z]+)|(\d+))$)/
why we need filter testbox?
to show in web in a specified format.
database: "vm-hixx-2p8g--zyh" web: "vm-hixx-2p8g"
i saw you another patch, it's used for compare_candidates
Thanks, Weitao
Yes, It to fix bug in web_backend. More emergency this. So I resend it.
Thanks, Zhang Yuhang
On Tue, Oct 20, 2020 at 11:19:42AM +0800, Zhang Yuhang wrote:
On Tue, Oct 20, 2020 at 11:13:20AM +0800, Lu Weitao wrote:
- if r =~ /(^.+--.+$)|(^vm-.*-\d\w*-(([a-zA-Z]+)|(\d+))$)/
why we need filter testbox?
to show in web in a specified format.
database: "vm-hixx-2p8g--zyh" web: "vm-hixx-2p8g"
i saw you another patch, it's used for compare_candidates
Thanks, Weitao
Yes, It to fix bug in web_backend. More emergency this. So I resend it.
fix bug is another thing, it's right to sent it in a new patch.
Thanks, Weitao
Thanks, Zhang Yuhang
On Tue, Oct 20, 2020 at 02:48:04PM +0800, Lu Weitao wrote:
On Tue, Oct 20, 2020 at 11:19:42AM +0800, Zhang Yuhang wrote:
On Tue, Oct 20, 2020 at 11:13:20AM +0800, Lu Weitao wrote:
- if r =~ /(^.+--.+$)|(^vm-.*-\d\w*-(([a-zA-Z]+)|(\d+))$)/
why we need filter testbox?
to show in web in a specified format.
database: "vm-hixx-2p8g--zyh" web: "vm-hixx-2p8g"
i saw you another patch, it's used for compare_candidates
Thanks, Weitao
Yes, It to fix bug in web_backend. More emergency this. So I resend it.
fix bug is another thing, it's right to sent it in a new patch.
Thanks, Weitao
OK.
Thanks, Zhang Yuhang