1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.blog.service.search;
35
36 import fr.paris.lutece.plugins.blog.business.Blog;
37 import fr.paris.lutece.plugins.blog.service.BlogService;
38 import fr.paris.lutece.plugins.blog.service.docsearch.BlogSearchService;
39 import fr.paris.lutece.plugins.blog.service.docsearch.DefaultBlogIndexer;
40 import fr.paris.lutece.portal.service.content.XPageAppService;
41 import fr.paris.lutece.portal.service.message.SiteMessageException;
42 import fr.paris.lutece.portal.service.search.SearchIndexer;
43 import fr.paris.lutece.portal.service.util.AppLogService;
44 import fr.paris.lutece.portal.service.util.AppPathService;
45 import fr.paris.lutece.portal.service.util.AppPropertiesService;
46 import fr.paris.lutece.util.url.UrlItem;
47
48 import org.apache.lucene.document.Document;
49
50 import java.io.IOException;
51 import java.util.ArrayList;
52 import java.util.List;
53
54
55
56
57 public class BlogSearchIndexer implements SearchIndexer
58 {
59 public static final String INDEXER_NAME = "BlogsIndexer";
60 public static final String SHORT_NAME = "hdoc";
61 private static final String BLOGS = "blogs";
62 private static final String INDEXER_DESCRIPTION = "Indexer service for blogs";
63 private static final String INDEXER_VERSION = "1.0.0";
64 private static final String PROPERTY_INDEXER_ENABLE = "blog.globalIndexer.enable";
65
66
67
68
69 @Override
70 public String getName( )
71 {
72 return INDEXER_NAME;
73 }
74
75
76
77
78 @Override
79 public String getDescription( )
80 {
81 return INDEXER_DESCRIPTION;
82 }
83
84
85
86
87 @Override
88 public String getVersion( )
89 {
90 return INDEXER_VERSION;
91 }
92
93
94
95
96 @Override
97 public boolean isEnable( )
98 {
99 String strEnable = AppPropertiesService.getProperty( PROPERTY_INDEXER_ENABLE );
100
101 return ( strEnable.equalsIgnoreCase( "true" ) );
102 }
103
104
105
106
107 @Override
108 public List<String> getListType( )
109 {
110 List<String> listType = new ArrayList<>( 1 );
111 listType.add( BLOGS );
112
113 return listType;
114 }
115
116
117
118
119 @Override
120 public String getSpecificSearchAppUrl( )
121 {
122 UrlItem url = new UrlItem( AppPathService.getPortalUrl( ) );
123 url.addParameter( XPageAppService.PARAM_XPAGE_APP, BLOGS );
124
125 return url.getUrl( );
126 }
127
128
129
130
131 @Override
132 public List<Document> getDocuments( String strDocumentId ) throws IOException, InterruptedException, SiteMessageException
133 {
134
135 int documentId;
136
137 try
138 {
139 documentId = Integer.parseInt( strDocumentId );
140 }
141 catch( NumberFormatException ne )
142 {
143 AppLogService.error( strDocumentId + " not parseable to an int", ne );
144
145 return new ArrayList<>( 0 );
146 }
147
148 Blog blog = BlogService.getInstance( ).loadBlog( documentId );
149 Document doc = DefaultBlogIndexer.getDocument( blog );
150
151 if ( doc != null )
152 {
153 List<Document> listDocument = new ArrayList<>( 1 );
154 listDocument.add( doc );
155
156 return listDocument;
157 }
158
159 return new ArrayList<>( 0 );
160 }
161
162
163
164
165 @Override
166 public void indexDocuments( ) throws IOException, InterruptedException, SiteMessageException
167 {
168 BlogSearchService.getInstance( ).processIndexing( true );
169 }
170
171 }