主页搜索功能的下一页修改
This commit is contained in:
parent
163abb70de
commit
e52026142a
|
@ -153,73 +153,7 @@ class WelcomeController < ApplicationController
|
||||||
def search
|
def search
|
||||||
@name = params[:q]
|
@name = params[:q]
|
||||||
@search_type = params[:search_type]
|
@search_type = params[:search_type]
|
||||||
case params[:search_type]
|
page = (params[:page] || 1).to_i
|
||||||
when 'all'
|
|
||||||
@alls = Elasticsearch::Model.search({
|
|
||||||
query: {
|
|
||||||
multi_match: {
|
|
||||||
query: @name,
|
|
||||||
type:"most_fields",
|
|
||||||
operator: "or",
|
|
||||||
fields: ['login', 'firstname','lastname','title','name','description^0.5','filename','subject','content^0.5']
|
|
||||||
}
|
|
||||||
},
|
|
||||||
highlight: {
|
|
||||||
pre_tags: ['<span class="c_red">'],
|
|
||||||
post_tags: ['</span>'],
|
|
||||||
fields: {
|
|
||||||
login: {},
|
|
||||||
firstname: {},
|
|
||||||
lastname: {},
|
|
||||||
title:{},
|
|
||||||
name:{},
|
|
||||||
description:{},
|
|
||||||
filename:{},
|
|
||||||
subject:{},
|
|
||||||
content:{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},[User,Syllabus,Course,Attachment,Project,Memo] ).page(params[:page] || 1).per(20).results
|
|
||||||
when 'user'
|
|
||||||
@users = User.search(@name).page(params[:page] || 1).per(20)
|
|
||||||
when 'syllabus'
|
|
||||||
@syllabuses = Syllabus.search(@name).page(params[:page] || 1).per(20).results
|
|
||||||
when 'project'
|
|
||||||
@projects = Project.search(@name).page(params[:page] || 1).per(20).results
|
|
||||||
when 'course'
|
|
||||||
@courses = Course.search(@name).page(params[:page] || 1).per(20).results
|
|
||||||
when 'attachment'
|
|
||||||
@attachments = Attachment.search(@name).page(params[:page] || 1).per(20).results
|
|
||||||
when 'memo'
|
|
||||||
@memos = Memo.search(@name).page(params[:page] || 1).per(20).results
|
|
||||||
else
|
|
||||||
@alls = Elasticsearch::Model.search({
|
|
||||||
query: {
|
|
||||||
multi_match: {
|
|
||||||
query: @name,
|
|
||||||
type:"most_fields",
|
|
||||||
operator: "or",
|
|
||||||
fields: ['login', 'firstname','lastname','title','name','description^0.5','filename','subject','content^0.5']
|
|
||||||
}
|
|
||||||
},
|
|
||||||
highlight: {
|
|
||||||
pre_tags: ['<span class="c_red">'],
|
|
||||||
post_tags: ['</span>'],
|
|
||||||
fields: {
|
|
||||||
login: {},
|
|
||||||
firstname: {},
|
|
||||||
lastname: {},
|
|
||||||
title:{},
|
|
||||||
name:{},
|
|
||||||
description:{},
|
|
||||||
filename:{},
|
|
||||||
subject:{},
|
|
||||||
content:{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},[User,Syllabus,Course,Attachment,Project,Memo] ).page(params[:page] || 1).per(20).results
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
@users_count = User.search(@name).results.total
|
@users_count = User.search(@name).results.total
|
||||||
@syllabus_count = Syllabus.search(@name).results.total
|
@syllabus_count = Syllabus.search(@name).results.total
|
||||||
|
@ -252,6 +186,109 @@ class WelcomeController < ApplicationController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},[User,Syllabus,Course,Attachment,Project,Memo] ).results.total
|
},[User,Syllabus,Course,Attachment,Project,Memo] ).results.total
|
||||||
|
|
||||||
|
|
||||||
|
case params[:search_type]
|
||||||
|
when 'all'
|
||||||
|
if (page-1)*20 > @total_count
|
||||||
|
page = 1
|
||||||
|
params[:page] = "1"
|
||||||
|
end
|
||||||
|
@alls = Elasticsearch::Model.search({
|
||||||
|
query: {
|
||||||
|
multi_match: {
|
||||||
|
query: @name,
|
||||||
|
type:"most_fields",
|
||||||
|
operator: "or",
|
||||||
|
fields: ['login', 'firstname','lastname','title','name','description^0.5','filename','subject','content^0.5']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
highlight: {
|
||||||
|
pre_tags: ['<span class="c_red">'],
|
||||||
|
post_tags: ['</span>'],
|
||||||
|
fields: {
|
||||||
|
login: {},
|
||||||
|
firstname: {},
|
||||||
|
lastname: {},
|
||||||
|
title:{},
|
||||||
|
name:{},
|
||||||
|
description:{},
|
||||||
|
filename:{},
|
||||||
|
subject:{},
|
||||||
|
content:{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},[User,Syllabus,Course,Attachment,Project,Memo] ).page(page).per(20).results
|
||||||
|
when 'user'
|
||||||
|
if (page-1)*20 > @users_count
|
||||||
|
page = 1
|
||||||
|
params[:page] = "1"
|
||||||
|
end
|
||||||
|
@users = User.search(@name).page(page).per(20)
|
||||||
|
when 'syllabus'
|
||||||
|
if (page-1)*20 > @syllabus_count
|
||||||
|
page = 1
|
||||||
|
params[:page] = "1"
|
||||||
|
end
|
||||||
|
@syllabuses = Syllabus.search(@name).page(page).per(20).results
|
||||||
|
when 'project'
|
||||||
|
if (page-1)*20 > @project_count
|
||||||
|
page = 1
|
||||||
|
end
|
||||||
|
@projects = Project.search(@name).page(page).per(20).results
|
||||||
|
when 'course'
|
||||||
|
if (page-1)*20 > @course_count
|
||||||
|
page = 1
|
||||||
|
params[:page] = "1"
|
||||||
|
end
|
||||||
|
@courses = Course.search(@name).page(page).per(20).results
|
||||||
|
when 'attachment'
|
||||||
|
if (page-1)*20 > @attach_count
|
||||||
|
page = 1
|
||||||
|
params[:page] = "1"
|
||||||
|
end
|
||||||
|
@attachments = Attachment.search(@name).page(page).per(20).results
|
||||||
|
when 'memo'
|
||||||
|
if (page-1)*20 > @memo_count
|
||||||
|
page = 1
|
||||||
|
params[:page] = "1"
|
||||||
|
end
|
||||||
|
@memos = Memo.search(@name).page(page).per(20).results
|
||||||
|
else
|
||||||
|
if (page-1)*20 > @total_count
|
||||||
|
page = 1
|
||||||
|
params[:page] = "1"
|
||||||
|
end
|
||||||
|
@alls = Elasticsearch::Model.search({
|
||||||
|
query: {
|
||||||
|
multi_match: {
|
||||||
|
query: @name,
|
||||||
|
type:"most_fields",
|
||||||
|
operator: "or",
|
||||||
|
fields: ['login', 'firstname','lastname','title','name','description^0.5','filename','subject','content^0.5']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
highlight: {
|
||||||
|
pre_tags: ['<span class="c_red">'],
|
||||||
|
post_tags: ['</span>'],
|
||||||
|
fields: {
|
||||||
|
login: {},
|
||||||
|
firstname: {},
|
||||||
|
lastname: {},
|
||||||
|
title:{},
|
||||||
|
name:{},
|
||||||
|
description:{},
|
||||||
|
filename:{},
|
||||||
|
subject:{},
|
||||||
|
content:{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},[User,Syllabus,Course,Attachment,Project,Memo] ).page(page).per(20).results
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# search_type = params[:search_type].to_sym unless search_condition.blank?
|
# search_type = params[:search_type].to_sym unless search_condition.blank?
|
||||||
# search_by = params[:search_by]
|
# search_by = params[:search_by]
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue