Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Backend
Commits
4b0b492d
Commit
4b0b492d
authored
Jan 22, 2014
by
Matija Obreza
Browse files
Default search on Accessions and AccessionAliases
parent
66d0394f
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/server/service/SearchService.java
View file @
4b0b492d
...
...
@@ -18,9 +18,10 @@ package org.genesys2.server.service;
import
org.hibernate.search.SearchException
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
public
interface
SearchService
{
Page
<?>
search
(
String
searchQuery
,
String
[]
fields
,
int
startAt
,
int
maxResult
s
)
throws
SearchException
;
Page
<?>
search
(
String
searchQuery
,
String
[]
fields
,
Pageable
pageable
,
Class
<?>
...
targetClas
s
)
throws
SearchException
;
}
src/main/java/org/genesys2/server/service/impl/SearchServiceImpl.java
View file @
4b0b492d
...
...
@@ -34,6 +34,7 @@ import org.hibernate.search.SearchException;
import
org.hibernate.search.jpa.FullTextEntityManager
;
import
org.hibernate.search.jpa.Search
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -46,14 +47,15 @@ public class SearchServiceImpl implements SearchService {
private
EntityManager
entityManager
;
/**
* @param classes
* @return
* @throws SearchException
*/
@Override
public
Page
<?>
search
(
String
searchQuery
,
String
[]
fields
,
int
page
,
int
pageSize
)
throws
SearchException
{
public
Page
<?>
search
(
String
searchQuery
,
String
[]
fields
,
Pageable
pageable
,
Class
<?>
...
classes
)
throws
SearchException
{
LOG
.
debug
(
"Searching for: "
+
searchQuery
);
LucenePage
<
Object
>
lucenePage
=
new
LucenePage
<
Object
>(
page
,
p
ageSize
);
LucenePage
<
Object
>
lucenePage
=
new
LucenePage
<
Object
>(
page
able
.
getPageNumber
(),
pageable
.
getP
ageSize
()
);
if
(
searchQuery
==
null
)
return
null
;
...
...
@@ -65,11 +67,11 @@ public class SearchServiceImpl implements SearchService {
try
{
luceneQuery
=
getLuceneQuery
(
searchQuery
,
fields
);
org
.
hibernate
.
search
.
jpa
.
FullTextQuery
query
=
ftEm
.
createFullTextQuery
(
luceneQuery
);
org
.
hibernate
.
search
.
jpa
.
FullTextQuery
query
=
ftEm
.
createFullTextQuery
(
luceneQuery
,
classes
);
lucenePage
.
setTotalElements
(
query
.
getResultSize
());
@SuppressWarnings
(
"unchecked"
)
List
<
Object
>
data
=
query
.
setMaxResults
(
pageSize
).
setFirstResult
(
page
*
pageSize
).
getResultList
();
List
<
Object
>
data
=
query
.
setMaxResults
(
pageable
.
getPageSize
()).
setFirstResult
(
pageable
.
getPageNumber
()
*
pageable
.
getPageSize
())
.
getResultList
();
prefetch
(
data
);
...
...
src/main/java/org/genesys2/server/servlet/controller/SearchController.java
View file @
4b0b492d
...
...
@@ -19,33 +19,55 @@ package org.genesys2.server.servlet.controller;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.genesys2.server.model.genesys.Accession
;
import
org.genesys2.server.model.genesys.AccessionAlias
;
import
org.genesys2.server.service.SearchService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Scope
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.ModelMap
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.util.HtmlUtils
;
@Controller
@
RequestMapping
(
"/search
"
)
@
Scope
(
"request
"
)
public
class
SearchController
{
public
static
final
Log
LOG
=
LogFactory
.
getLog
(
SearchController
.
class
);
@Autowired
private
SelectionBean
selectionBean
;
@Autowired
SearchService
searchService
;
@RequestMapping
@RequestMapping
(
"/search"
)
public
String
find
(
ModelMap
model
,
@RequestParam
(
required
=
false
,
value
=
"q"
)
String
searchQuery
,
@RequestParam
(
value
=
"page"
,
required
=
false
,
defaultValue
=
"1"
)
int
page
)
{
model
.
addAttribute
(
"q"
,
HtmlUtils
.
htmlEscape
(
searchQuery
)
)
;
model
.
addAttribute
(
"q"
,
searchQuery
);
if
(!
StringUtils
.
isBlank
(
searchQuery
))
{
LOG
.
info
(
"Searching for: "
+
searchQuery
);
Page
<?>
x
=
searchService
.
search
(
searchQuery
,
new
String
[]
{
"title"
,
"body"
,
"description"
},
page
-
1
,
50
);
Page
<?>
x
=
searchService
.
search
(
searchQuery
,
new
String
[]
{
"title"
,
"body"
,
"description"
},
new
PageRequest
(
page
-
1
,
50
)
)
;
model
.
addAttribute
(
"pagedData"
,
x
);
}
return
"/search/index"
;
}
@RequestMapping
(
"/acn/search"
)
public
String
findAccession
(
ModelMap
model
,
@RequestParam
(
required
=
false
,
value
=
"q"
)
String
searchQuery
,
@RequestParam
(
value
=
"page"
,
required
=
false
,
defaultValue
=
"1"
)
int
page
)
{
model
.
addAttribute
(
"q"
,
searchQuery
);
if
(!
StringUtils
.
isBlank
(
searchQuery
))
{
LOG
.
info
(
"Searching for: "
+
searchQuery
);
Page
<?>
x
=
searchService
.
search
(
searchQuery
,
new
String
[]
{
"title"
,
"body"
,
"description"
},
new
PageRequest
(
page
-
1
,
50
),
Accession
.
class
,
AccessionAlias
.
class
);
model
.
addAttribute
(
"pagedData"
,
x
);
}
model
.
addAttribute
(
"selection"
,
selectionBean
);
return
"/search/accessions"
;
}
}
src/main/webapp/WEB-INF/decorator/header.jsp
View file @
4b0b492d
...
...
@@ -7,7 +7,7 @@
<a
href=
"
<c:url
value=
"/"
/>
"
><img
src=
"
<c:url
value=
"/html/images/logo_genesys.png"
/>
"
alt=
"Genesys - Gateway to Genetic Resources"
title=
"Genesys - Gateway to Genetic Resources"
/></a>
</div>
<form
class=
"navbar-form navbar-left"
role=
"search"
id=
"search"
method=
"get"
action=
"
<c:url
value=
"/search"
/>
"
>
<form
class=
"navbar-form navbar-left"
role=
"search"
id=
"search"
method=
"get"
action=
"
<c:url
value=
"/
acn/
search"
/>
"
>
<div
class=
"form-group"
>
<input
type=
"text"
class=
"form-control"
name=
"q"
placeholder=
"
<spring:message
code=
"search.input.placeholder"
/>
"
>
</div>
...
...
src/main/webapp/WEB-INF/jsp/search/accessions.jsp
0 → 100644
View file @
4b0b492d
<!DOCTYPE html>
<%@include
file=
"/WEB-INF/jsp/init.jsp"
%>
<%@ taglib
prefix=
"sec"
uri=
"http://www.springframework.org/security/tags"
%>
<html>
<head>
<title><spring:message
code=
"search.page.title"
/></title>
</head>
<body>
<h1><spring:message
code=
"search.page.title"
/></h1>
<div
class=
"main-col-header clearfix"
>
<div
class=
"nav-header"
>
<div
class=
"results"
><spring:message
code=
"paged.totalElements"
arguments=
"
${
pagedData
.
totalElements
}
"
/></div>
<div
class=
"pagination"
>
<spring:message
code=
"paged.pageOfPages"
arguments=
"
${
pagedData
.
number
+
1
}
,${pagedData.totalPages}"
/>
<a
class=
"${pagedData.number eq 0 ? 'disabled' :''}"
href=
"?q=${q}&page=${pagedData.number eq 0 ? 1 : pagedData.number}"
><spring:message
code=
"pagination.previous-page"
/></a>
<a
href=
"?q=${q}&page=${pagedData.number + 2}"
><spring:message
code=
"pagination.next-page"
/></a>
</div>
</div>
</div>
<div
class=
"applied-filters"
>
<form
class=
""
method=
"get"
action=
"
<c:url
value=
"/acn/search"
/>
"
>
<div
class=
"row"
>
<div
class=
"col-md-4"
><input
type=
"text"
name=
"q"
class=
"form-control"
value=
"
<c:out
value=
"
${
q
}
"
/>
"
/></div>
<div
class=
"col-md-2"
><input
type=
"submit"
value=
"
<spring:message
code=
"search.button.label"
/>
"
class=
"btn"
/></div>
</div>
</form>
</div>
<c:if
test=
"
${
pagedData
ne
null
and
pagedData
.
totalElements
gt
0
}
"
>
<table
class=
"accessions"
>
<thead>
<tr>
<td
class=
"idx-col"
></td>
<c:if
test=
"
${
selection
ne
null
}
"
>
<td
/>
</c:if>
<td><spring:message
code=
"accession.accessionName"
/></td>
<td><spring:message
code=
"accession.otherNames"
/></td>
<td><spring:message
code=
"accession.taxonomy"
/></td>
<td
class=
"notimportant"
><spring:message
code=
"accession.origin"
/></td>
<td
class=
"notimportant"
><spring:message
code=
"accession.sampleStatus"
/></td>
<td
class=
"notimportant"
><spring:message
code=
"accession.holdingInstitute"
/></td>
</tr>
</thead>
<tbody>
<c:forEach
items=
"
${
pagedData
.
content
}
"
var=
"searchResult"
varStatus=
"status"
>
<c:set
value=
"
${
searchResult
.
getClass
().
simpleName
}
"
var=
"clazz"
/>
<c:if
test=
"
${
clazz
.
contains
(
'_$$_'
)
}
"
>
<c:set
var=
"clazz"
value=
"
${
clazz
.
substring
(
0
,
clazz
.
indexOf
(
'_$$_'
))
}
"
/>
</c:if>
<c:choose>
<c:when
test=
"
${
clazz
eq
'Accession'
}
"
>
<c:set
var=
"accession"
value=
"
${
searchResult
}
"
/>
<c:set
var=
"name"
value=
""
/>
</c:when>
<c:when
test=
"
${
clazz
eq
'AccessionAlias'
}
"
>
<c:set
var=
"accession"
value=
"
${
searchResult
.
accession
}
"
/>
<c:set
var=
"name"
value=
"
${
searchResult
.
name
}
"
/>
</c:when>
<c:otherwise>
<c:remove
var=
"accession"
/>
<c:remove
var=
"name"
/>
</c:otherwise>
</c:choose>
<tr
class=
"acn"
>
<td
class=
"idx-col"
>
${status.count + pagedData.size * pagedData.number}
</td>
<c:if
test=
"
${
selection
ne
null
}
"
>
<td
class=
"sel ${selection.containsId(accession.id) ? 'picked' : ''}"
x-aid=
"${accession.id}"
></td>
</c:if>
<td><a
href=
"
<c:url
value=
"/acn/id/${accession.id}"
/>
"
><b>
<c:out
value=
"
${
accession
.
accessionName
}
"
/>
</b></a></td>
<td><c:out
value=
"
${
name
}
"
/></td>
<%-- <td><a href="<c:url value="/acn/t/${accession.taxonomy.genus}/${accession.taxonomy.species}" />"><c:out value="${accession.taxonomy.taxonName}" /></a></td> --%>
<td><c:out
value=
"
${
accession
.
taxonomy
.
taxonName
}
"
/></td>
<%-- <td class="notimportant"><a href="<c:url value="/geo/${accession.origin.toLowerCase()}" />"><c:out value="${accession.countryOfOrigin.name}" /></a></td> --%>
<td
class=
"notimportant"
><c:out
value=
"
${
accession
.
countryOfOrigin
.
getName
(
pageContext
.
response
.
locale
)
}
"
/></td>
<td
class=
"notimportant"
><spring:message
code=
"accession.sampleStatus.${accession.sampleStatus}"
/></td>
<td
class=
"notimportant"
><a
href=
"
<c:url
value=
"/wiews/${accession.institute.code.toLowerCase()}"
/>
"
><c:out
value=
"
${
accession
.
institute
.
code
}
"
/></a></td>
</tr>
</c:forEach>
</tbody>
</table>
</c:if>
</body>
</html>
\ No newline at end of file
src/main/webapp/WEB-INF/jsp/search/index.jsp
View file @
4b0b492d
...
...
@@ -10,21 +10,26 @@
<body>
<h1><spring:message
code=
"search.page.title"
/></h1>
<form
class=
"form-search"
method=
"get"
action=
"
<c:url
value=
"/search"
/>
"
>
<input
type=
"text"
name=
"q"
class=
""
value=
"
<c:out
value=
"
${
q
}
"
/>
"
/>
<input
type=
"submit"
value=
"
<spring:message
code=
"search.button.label"
/>
"
class=
"btn"
/>
<div
class=
"main-col-header clearfix"
>
<form
class=
""
method=
"get"
action=
"
<c:url
value=
"/search"
/>
"
>
<div
class=
"input-group col-lg-3"
><span
class=
"input-group-btn"
><input
type=
"text"
name=
"q"
class=
"span3 form-control"
value=
"
<c:out
value=
"
${
q
}
"
/>
"
/><input
type=
"submit"
value=
"
<spring:message
code=
"search.button.label"
/>
"
class=
"btn"
/></span></div>
</form>
</div>
<c:if
test=
"
${
pagedData
.
totalElements
eq
0
}
"
>
<div
class=
"alert alert-info"
><spring:message
code=
"search.no-results"
/></div>
</c:if>
<c:if
test=
"
${
pagedData
ne
null
and
pagedData
.
totalElements
gt
0
}
"
>
<div
class=
"nav-header"
>
<spring:message
code=
"paged.totalElements"
arguments=
"
${
pagedData
.
totalElements
}
"
/>
<br
/>
<spring:message
code=
"paged.pageOfPages"
arguments=
"
${
pagedData
.
number
+
1
}
,${pagedData.totalPages}"
/>
<a
class=
"${pagedData.number eq 0 ? 'disabled' :''}"
href=
"?q=${q}&page=${pagedData.number eq 0 ? 1 : pagedData.number}"
><spring:message
code=
"pagination.previous-page"
/></a>
<a
href=
"?q=${q}&page=${pagedData.number + 2}"
><spring:message
code=
"pagination.next-page"
/></a>
<div
class=
"main-col-header clearfix"
>
<div
class=
"nav-header pull-left"
>
<div
class=
"results"
><spring:message
code=
"paged.totalElements"
arguments=
"
${
pagedData
.
totalElements
}
"
/></div>
<div
class=
"pagination"
>
<spring:message
code=
"paged.pageOfPages"
arguments=
"
${
pagedData
.
number
+
1
}
,${pagedData.totalPages}"
/>
<a
class=
"${pagedData.number eq 0 ? 'disabled' :''}"
href=
"?q=${q}&page=${pagedData.number eq 0 ? 1 : pagedData.number}"
><spring:message
code=
"pagination.previous-page"
/></a>
<a
href=
"?q=${q}&page=${pagedData.number + 2}"
><spring:message
code=
"pagination.next-page"
/></a>
</div>
</div>
</div>
<ul
class=
"funny-list"
>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment