Migrated to solr 1.4. Added a filter factory so that solr can use the greek lower...
[pithos] / src / gr / ebs / gss / server / ejb / ExternalAPIBean.java
index ca7db0d..20da756 100644 (file)
@@ -1811,7 +1811,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                List<FileHeader> result = new ArrayList<FileHeader>();
                try {
                        CommonsHttpSolrServer solr = new CommonsHttpSolrServer(getConfiguration().getString("solr.url"));
-                       SolrQuery solrQuery = new SolrQuery(query);
+                       SolrQuery solrQuery = new SolrQuery(escapeCharacters(normalizeSearchQuery(query)));
                        QueryResponse response = solr.query(solrQuery);
                        SolrDocumentList results = response.getResults();
                        User user = getUser(userId);
@@ -2087,6 +2087,24 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
        }
 
        @Override
+       public void refreshSolrIndex() {
+               try {
+                       CommonsHttpSolrServer solr = new CommonsHttpSolrServer(getConfiguration().getString("solr.url"));
+                       
+                       List<Long> fileIds = dao.getAllFileIds();
+                       for (Long id : fileIds) {
+                               postFileToSolr(id);
+                       }
+                       solr.optimize();
+                       solr.commit();
+               } catch (IOException e) {
+                       throw new EJBException(e);
+               } catch (SolrServerException e) {
+                       throw new EJBException(e);
+               }
+       }
+
+       @Override
        public FileHeaderDTO createFile(Long userId, Long folderId, String name, String mimeType, long fileSize, String filePath)
                        throws DuplicateNameException, ObjectNotFoundException, GSSIOException,
                        InsufficientPermissionsException, QuotaExceededException {
@@ -2631,4 +2649,16 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                result.append(filename);
                return result.toString();
        }
+
+       private String normalizeSearchQuery(String query) {
+               if (query.contains("*"))
+                       return query.toLowerCase().replace('ά', 'α').replace('έ', 'ε').replace('ί', 'ι').replace('ή', 'η').replace('ύ', 'υ')
+                                       .replace('ό', 'ο').replace('ς', 'σ').replace('ώ', 'ω').replace('ϊ', 'ι').replace('ϋ', 'υ');
+               else
+                       return query;
+       }
+       
+       private String escapeCharacters(String text) {
+               return text.replaceAll(":", "\\\\:");
+       }
 }