From c9ae269ab75ed662a5d40a70f8412fc369fa79e2 Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Sun, 10 Jul 2016 09:37:24 +0200 Subject: [PATCH] javadoc updated --- .../imixs/workflow/lucene/LucenePlugin.java | 4 -- .../workflow/lucene/LuceneSearchService.java | 24 +++---- .../workflow/lucene/LuceneUpdateService.java | 65 ++++++------------- 3 files changed, 28 insertions(+), 65 deletions(-) diff --git a/imixs-adapters-lucene-ejb/src/main/java/org/imixs/workflow/lucene/LucenePlugin.java b/imixs-adapters-lucene-ejb/src/main/java/org/imixs/workflow/lucene/LucenePlugin.java index 0d1dd47..b904cb9 100644 --- a/imixs-adapters-lucene-ejb/src/main/java/org/imixs/workflow/lucene/LucenePlugin.java +++ b/imixs-adapters-lucene-ejb/src/main/java/org/imixs/workflow/lucene/LucenePlugin.java @@ -47,8 +47,6 @@ * * @see LuceneUpdateService * @author rsoika - * @version 4.5.1 (Lucene) - * */ public class LucenePlugin extends AbstractPlugin { public static String LUCENE_UPDATE_SERVICE_NOT_FOUND = "LUCENE_UPDATE_SERVICE_NOT_FOUND"; @@ -92,8 +90,6 @@ public void init(WorkflowContext actx) throws PluginException { public int run(ItemCollection documentContext, ItemCollection activity) throws PluginException { logger.fine("LucenePlugin: updating '" + documentContext.getUniqueID() + "'"); - // logger.info("Lucene - // ImplementationVersion="+LucenePackage.get().getImplementationVersion()); // compute next $processid to be added correctly into the search index int nextProcessID = activity.getItemValueInteger("numnextprocessid"); int currentProcessID = documentContext.getItemValueInteger("$processid"); diff --git a/imixs-adapters-lucene-ejb/src/main/java/org/imixs/workflow/lucene/LuceneSearchService.java b/imixs-adapters-lucene-ejb/src/main/java/org/imixs/workflow/lucene/LuceneSearchService.java index 5a7f192..dce937a 100644 --- a/imixs-adapters-lucene-ejb/src/main/java/org/imixs/workflow/lucene/LuceneSearchService.java +++ b/imixs-adapters-lucene-ejb/src/main/java/org/imixs/workflow/lucene/LuceneSearchService.java @@ -33,8 +33,6 @@ import java.util.List; import java.util.Properties; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import javax.annotation.PostConstruct; import javax.annotation.security.DeclareRoles; @@ -69,16 +67,13 @@ * reason the EJB is creating a new IndexSearch per-search. * * The service provides a set of public methods which can be used to query - * workitems or collections of workitems. - * - * Updated to version 4.5.1 - * - * The singleton pattern is used to avoid conflicts within multi thread - * szenarios. + * workitems or collections of workitems. A search term can be escaped by + * calling the method escpeSearchTerm. This method prepends a + * \ for those characters that QueryParser expects to be escaped. * * @see http://stackoverflow.com/questions/34880347/why-did-lucene-indexwriter- * did-not-update-the-index-when-called-from-a-web-modul - * @version 1.0 + * @version 2.0 * @author rsoika */ @DeclareRoles({ "org.imixs.ACCESSLEVEL.NOACCESS", "org.imixs.ACCESSLEVEL.READERACCESS", @@ -249,9 +244,7 @@ public List search(String sSearchTerm, WorkflowService workflowS Directory createIndexDirectory(Properties prop) throws IOException { logger.fine("lucene createIndexDirectory..."); - /** - * Read configuration - */ + // read configuration String sLuceneLockFactory = prop.getProperty("lucence.lockFactory"); String sIndexDir = prop.getProperty("lucence.indexDir"); @@ -324,18 +317,17 @@ QueryParser createQueryParser(Properties prop) { } /** - * This helper method escapes wildcard tokens found in a lucene search term. The - * method can be used by clients to prepare a search phrase. + * This helper method escapes wildcard tokens found in a lucene search term. + * The method can be used by clients to prepare a search phrase. * * @param searchTerm * @return */ public static String escapeSearchTerm(String searchTerm) { - if (searchTerm == null || searchTerm.isEmpty()) { return searchTerm; } - + return QueryParser.escape(searchTerm); } diff --git a/imixs-adapters-lucene-ejb/src/main/java/org/imixs/workflow/lucene/LuceneUpdateService.java b/imixs-adapters-lucene-ejb/src/main/java/org/imixs/workflow/lucene/LuceneUpdateService.java index a213c11..a808d18 100644 --- a/imixs-adapters-lucene-ejb/src/main/java/org/imixs/workflow/lucene/LuceneUpdateService.java +++ b/imixs-adapters-lucene-ejb/src/main/java/org/imixs/workflow/lucene/LuceneUpdateService.java @@ -64,12 +64,11 @@ import org.imixs.workflow.jee.util.PropertyService; /** - * The LuceneUpdateService is a singleton EJB providing a service to update the - * lucene index. - * - * With the method addWorkitem() a ItemCollection can be added to a lucene - * search index. The service init method reads the property file - * 'imixs.properties' from the current classpath to determine the configuration. + * The LuceneUpdateService provides methods to write Imixs Workitems into a + * Lucene search index. With the method addWorkitem() a + * ItemCollection can be added to a lucene search index. The service init method + * reads the property file 'imixs.properties' from the current classpath to + * determine the configuration. * * * - * If the service is used also by the LucenPlugin + * The singleton pattern is used to avoid conflicts within multi-thread + * scenarios. The service is used by the LucenPlugin to update the lucene index + * during a workflow processing step. * - * The singleton pattern is used to avoid conflicts within multi thread - * szenarios. * * @see http://stackoverflow.com/questions/34880347/why-did-lucene-indexwriter- * did-not-update-the-index-when-called-from-a-web-modul * @see LucenePlugin - * @version 1.0 + * @version 1.2 * @author rsoika */ @Singleton @@ -116,14 +116,8 @@ public class LuceneUpdateService { @PostConstruct void init() { - // try loading imixs-search properties + // read configuration properties = propertyService.getProperties(); - - /** - * Read configuration - */ - // String sLuceneVersion = prop.getProperty("Version", "LUCENE_45"); - indexDirectoryPath = properties.getProperty("lucence.indexDir"); luceneLockFactory = properties.getProperty("lucence.lockFactory"); @@ -176,21 +170,16 @@ void init() { */ public boolean updateWorkitem(ItemCollection documentContext) throws PluginException { List workitems = new ArrayList(); - workitems.add(documentContext); - updateWorklist(workitems); - return true; } /** - * This method updates the search index for a collection of workitems. - * - * For each workitem the method test if it did match the conditions to be - * added into the search index. If the workitem did not match the conditions - * the workitem will be removed from the index. - * + * This method updates the search index for a collection of workitems. For + * each workitem the method test if it did match the conditions to be added + * into the search index. If the workitem did not match the conditions the + * workitem will be removed from the index. * * @param worklist * of ItemCollections to be indexed @@ -203,9 +192,7 @@ public boolean updateWorklist(Collection worklist) throws Plugin long ltime = System.currentTimeMillis(); try { awriter = createIndexWriter(); - // add workitem to search index.... - for (ItemCollection workitem : worklist) { // create term Term term = new Term("$uniqueid", workitem.getItemValueString("$uniqueid")); @@ -221,14 +208,11 @@ public boolean updateWorklist(Collection worklist) throws Plugin } } } catch (IOException luceneEx) { - // close writer! logger.warning("lucene error: " + luceneEx.getMessage()); - throw new PluginException(LucenePlugin.class.getSimpleName(), INVALID_INDEX, "Unable to update lucene search index", luceneEx); - } finally { - + // close writer! if (awriter != null) { logger.fine("lucene close writer"); try { @@ -240,7 +224,6 @@ public boolean updateWorklist(Collection worklist) throws Plugin throw new PluginException(LucenePlugin.class.getSimpleName(), INVALID_INDEX, "Unable to update lucene search index", e); } - } } @@ -287,10 +270,8 @@ public void removeWorkitem(String uniqueID) throws PluginException { * @return */ public boolean matchConditions(ItemCollection aworktiem) { - String typePattern = properties.getProperty("lucence.matchingType"); String processIDPattern = properties.getProperty("lucence.matchingProcessID"); - String type = aworktiem.getItemValueString("Type"); String sPid = aworktiem.getItemValueInteger("$Processid") + ""; @@ -303,7 +284,6 @@ public boolean matchConditions(ItemCollection aworktiem) { // test $processid pattern if (processIDPattern != null && !"".equals(processIDPattern) && !sPid.matches(processIDPattern)) { logger.fine("Lucene $processid '" + sPid + "' did not match pattern '" + processIDPattern + "'"); - return false; } return true; @@ -322,15 +302,11 @@ public boolean matchConditions(ItemCollection aworktiem) { * @throws Exception */ IndexWriter createIndexWriter() throws IOException { - - /** - * Now create a IndexWriter Instance - */ + // create a IndexWriter Instance Directory indexDir = createIndexDirectory(); - // Analyzer analyzer = new StandardAnalyzer(); - // IndexWriterConfig indexWriterConfig = new - // IndexWriterConfig(Version.LATEST, new StandardAnalyzer()); + // we switched form StandardAnalyzer() to classicAnalyser + // see issue #25 IndexWriterConfig indexWriterConfig = new IndexWriterConfig(Version.LATEST, new ClassicAnalyzer()); // set the WriteLockTimeout to wait for a write lock (in milliseconds) @@ -403,8 +379,7 @@ Document createDocument(ItemCollection aworkitem) { String sValue = null; Document doc = new Document(); // combine all search fields from the search field list into one field - // ('content') - // for the lucene document + // ('content') for the lucene document String sContent = ""; for (String aFieldname : searchFieldList) { sValue = "";