Skip to content

Commit

Permalink
javadoc updated
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoika committed Jul 10, 2016
1 parent e4c868a commit c9ae269
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 <code>escpeSearchTerm</code>. This method prepends a
* <code>\</code> 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",
Expand Down Expand Up @@ -249,9 +244,7 @@ public List<ItemCollection> 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");

Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,29 @@
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 <code>addWorkitem()</code> 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.
*
* <ul>
* <li>The property "IndexDir" defines the location of the lucene index
* <li>The property "FulltextFieldList" lists all fields which should be
* searchable after a workitem was updated
* <li>The property "IndexFieldList" lists all fields which should be indexed as
* keywords by the lucene search engine
* </ul>
*
* 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
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -176,21 +170,16 @@ void init() {
*/
public boolean updateWorkitem(ItemCollection documentContext) throws PluginException {
List<ItemCollection> workitems = new ArrayList<ItemCollection>();

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
Expand All @@ -203,9 +192,7 @@ public boolean updateWorklist(Collection<ItemCollection> 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"));
Expand All @@ -221,14 +208,11 @@ public boolean updateWorklist(Collection<ItemCollection> 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 {
Expand All @@ -240,7 +224,6 @@ public boolean updateWorklist(Collection<ItemCollection> worklist) throws Plugin
throw new PluginException(LucenePlugin.class.getSimpleName(), INVALID_INDEX,
"Unable to update lucene search index", e);
}

}
}

Expand Down Expand Up @@ -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") + "";

Expand All @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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 = "";
Expand Down

0 comments on commit c9ae269

Please sign in to comment.