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
dc65b0ca
Commit
dc65b0ca
authored
Sep 16, 2013
by
Matija Obreza
Browse files
Reindex one entity, FaoInstitute lucene bridge
parent
42d0186b
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/crophub/rest/common/lucene/genesys/FaoInstituteBridge.java
0 → 100644
View file @
dc65b0ca
package
org.crophub.rest.common.lucene.genesys
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.lucene.document.Document
;
import
org.apache.lucene.document.Field
;
import
org.crophub.rest.common.model.impl.FaoInstitute
;
import
org.hibernate.search.bridge.FieldBridge
;
import
org.hibernate.search.bridge.LuceneOptions
;
public
class
FaoInstituteBridge
implements
FieldBridge
{
public
static
final
Log
LOG
=
LogFactory
.
getLog
(
FaoInstituteBridge
.
class
);
@Override
public
void
set
(
String
name
,
Object
value
,
Document
document
,
LuceneOptions
luceneOptions
)
{
// In this particular class the name of the new field was passed
// from the name field of the ClassBridge Annotation. This is not
// a requirement. It just works that way in this instance. The
// actual name could be supplied by hard coding it below.
FaoInstitute
institute
=
(
FaoInstitute
)
value
;
StringDocument
sd
=
new
StringDocument
();
sd
.
append
(
institute
.
getAcronym
());
sd
.
append
(
institute
.
getCode
());
sd
.
append
(
institute
.
getFullName
());
if
(
institute
.
getCountry
()
!=
null
)
sd
.
append
(
institute
.
getCountry
().
getName
());
LOG
.
debug
(
"IDX."
+
name
+
" = "
+
sd
.
toString
());
Field
field
=
new
Field
(
name
,
sd
.
toString
(),
luceneOptions
.
getStore
(),
luceneOptions
.
getIndex
(),
luceneOptions
.
getTermVector
());
field
.
setBoost
(
luceneOptions
.
getBoost
());
document
.
add
(
field
);
}
}
src/main/java/org/crophub/rest/common/model/impl/FaoInstitute.java
View file @
dc65b0ca
...
...
@@ -28,7 +28,9 @@ import javax.persistence.ManyToOne;
import
javax.persistence.Table
;
import
javax.persistence.UniqueConstraint
;
import
org.crophub.rest.common.lucene.genesys.FaoInstituteBridge
;
import
org.hibernate.annotations.Index
;
import
org.hibernate.search.annotations.ClassBridge
;
import
org.hibernate.search.annotations.DocumentId
;
import
org.hibernate.search.annotations.Field
;
import
org.hibernate.search.annotations.Indexed
;
...
...
@@ -38,6 +40,7 @@ import org.hibernate.search.annotations.Store;
@Table
(
name
=
"faoinstitute"
,
uniqueConstraints
=
@UniqueConstraint
(
columnNames
=
{
"code"
}))
@org
.
hibernate
.
annotations
.
Table
(
appliesTo
=
"faoinstitute"
,
indexes
=
{
@Index
(
columnNames
=
{
"code"
},
name
=
"code_FAOINSTITUTE"
)
})
@Indexed
@ClassBridge
(
name
=
"body"
,
impl
=
FaoInstituteBridge
.
class
)
public
class
FaoInstitute
extends
GeoEntity
implements
java
.
io
.
Serializable
{
/**
...
...
src/main/java/org/crophub/rest/common/service/LuceneIndexer.java
View file @
dc65b0ca
...
...
@@ -4,4 +4,6 @@ public interface LuceneIndexer {
void
reindexEverything
();
void
reindexEntity
(
String
entityName
);
}
src/main/java/org/crophub/rest/common/service/impl/LuceneIndexerImpl.java
View file @
dc65b0ca
...
...
@@ -22,6 +22,30 @@ public class LuceneIndexerImpl implements LuceneIndexer {
@Autowired
private
EntityManagerFactory
entityManagerFactory
;
@Override
@PreAuthorize
(
"hasRole('ADMINISTRATOR')"
)
public
void
reindexEntity
(
String
entityName
)
{
LOG
.
info
(
"Indexing "
+
entityName
+
" in the DB..."
);
StopWatch
timer
=
new
StopWatch
();
Session
session
=
(
Session
)
this
.
entityManagerFactory
.
createEntityManager
().
getDelegate
();
FullTextSession
fullTextSession
=
Search
.
getFullTextSession
(
session
);
try
{
timer
.
start
();
LOG
.
info
(
"Start and Wait..."
);
fullTextSession
.
createIndexer
(
Class
.
forName
(
entityName
)).
startAndWait
();
timer
.
stop
();
}
catch
(
InterruptedException
e
)
{
LOG
.
error
(
e
);
}
catch
(
ClassNotFoundException
e
)
{
LOG
.
error
(
e
);
}
finally
{
fullTextSession
.
close
();
}
LOG
.
info
(
"Finished indexing after: "
+
timer
.
getTime
()
+
"ms"
);
}
@Override
@PreAuthorize
(
"hasRole('ADMINISTRATOR')"
)
public
void
reindexEverything
()
{
...
...
src/main/java/org/crophub/rest/servlet/controller/AdminController.java
View file @
dc65b0ca
...
...
@@ -27,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
@Controller
@RequestMapping
(
"/admin"
)
...
...
@@ -72,5 +73,11 @@ public class AdminController {
luceneIndexer
.
reindexEverything
();
return
"redirect:/admin/"
;
}
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/reindexEntity"
)
public
String
reindexEntities
(
@RequestParam
(
"entity"
)
String
entityName
)
{
luceneIndexer
.
reindexEntity
(
entityName
);
return
"redirect:/admin/"
;
}
}
src/main/webapp/WEB-INF/jsp/admin/index.jsp
View file @
dc65b0ca
...
...
@@ -22,6 +22,18 @@
<form
method=
"post"
action=
"
<c:url
value=
"/admin/reindexEverything"
/>
"
>
<input
type=
"submit"
value=
"Reindex search indexes"
/>
</form>
<form
method=
"post"
action=
"
<c:url
value=
"/admin/reindexEntity"
/>
"
>
<select
name=
"entity"
>
<option
value=
"org.crophub.rest.common.model.impl.Country"
>
Countries
</option>
<option
value=
"org.crophub.rest.common.model.impl.FaoInstitute"
>
WIEWS Institutes
</option>
<option
value=
"org.crophub.rest.common.model.impl.ActivityPost"
>
Posts
</option>
<option
value=
"org.crophub.rest.common.model.impl.Article"
>
Articles
</option>
<option
value=
"org.crophub.rest.common.model.genesys.Accession"
>
Accessions
</option>
</select>
<input
type=
"submit"
value=
"Reindex search indexes"
/>
</form>
</sec:authorize>
</body>
...
...
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