1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.hack23.cia.service.data.impl;
20
21 import javax.persistence.EntityManager;
22 import javax.persistence.PersistenceContext;
23
24 import org.hibernate.search.jpa.FullTextEntityManager;
25 import org.hibernate.search.jpa.Search;
26 import org.springframework.stereotype.Repository;
27
28 import com.hack23.cia.service.data.api.SearchIndexer;
29
30
31
32
33 @Repository
34 final class SearchIndexerImpl implements SearchIndexer {
35
36
37 private static final int TIMEOUT_IN_SECONDS = 900;
38
39
40 @PersistenceContext(name = "ciaPersistenceUnit")
41 private EntityManager entityManager;
42
43
44 private FullTextEntityManager fullTextEntityManager;
45
46
47
48
49 public SearchIndexerImpl() {
50 super();
51 }
52
53
54
55
56
57
58 private FullTextEntityManager getFullTextEntityManager() {
59 if (fullTextEntityManager == null) {
60 fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
61 }
62 return fullTextEntityManager;
63 }
64
65 @Override
66 public void updateSearchIndex() throws InterruptedException {
67 getFullTextEntityManager().createIndexer().transactionTimeout(TIMEOUT_IN_SECONDS).startAndWait();
68 }
69 }