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