Skip to content

Commit

Permalink
bug fixes - optimized code
Browse files Browse the repository at this point in the history
Issue imixs#554
  • Loading branch information
rsoika committed Sep 4, 2019
1 parent 4a1f149 commit 0c2dda6
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ private void loadProperties() {
*
* <ul>
* <li>lucence.fulltextFieldList - index.fields</li>
* <li>lucence.indexFieldListAnalyze - index.fields.analyse</li>
* <li>lucence.indexFieldListNoAnalyze - index.fields.noanalyse</li>
* <li>lucence.indexFieldListAnalyze - index.fields.analyze</li>
* <li>lucence.indexFieldListNoAnalyze - index.fields.noanalyze</li>
* <li>lucence.indexFieldListStore - index.fields.store</li>
*
* <li>lucence.defaultOperator - index.operator</li>
Expand All @@ -126,10 +126,10 @@ private String getAlternative(String key) {
if ("index.fields".equals(key)) {
return "lucence.fulltextFieldList";
}
if ("index.fields.analyse".equals(key)) {
if ("index.fields.analyze".equals(key)) {
return "lucence.indexFieldListAnalyze";
}
if ("index.fields.noanalyse".equals(key)) {
if ("index.fields.noanalyze".equals(key)) {
return "lucence.indexFieldListNoAnalyze";
}
if ("index.fields.store".equals(key)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
*
* <ul>
* <li>index.fields - content which will be indexed</li>
* <li>index.fields.analyse - fields indexed as analyzed keyword fields</li>
* <li>index.fields.noanalyse - fields indexed without analyze</li>
* <li>index.fields.analyze - fields indexed as analyzed keyword fields</li>
* <li>index.fields.noanalyze - fields indexed without analyze</li>
* <li>index.fields.store - fields stored in the index</li>
* <li>index.operator - default operator</li>
* <li>index.splitwhitespace - split text on whitespace prior to analysis</li>
Expand All @@ -67,7 +67,7 @@
public class SchemaService {

/*
* index.fields index.fields.analyse index.fields.noanalyse index.fields.store
* index.fields index.fields.analyze index.fields.noanalyze index.fields.store
*
* index.operator index.splitwhitespace
*
Expand All @@ -82,11 +82,11 @@ public class SchemaService {

@Inject
@ConfigProperty(name = "index.fields.analyze", defaultValue = "")
private String indexFieldsAnalyse;
private String indexFieldsAnalyze;

@Inject
@ConfigProperty(name = "index.fields.noanalyze", defaultValue = "")
private String indexFieldsNoAnalyse;
private String indexFieldsNoAnalyze;

@Inject
@ConfigProperty(name = "index.fields.store", defaultValue = "")
Expand All @@ -96,14 +96,14 @@ public class SchemaService {
private DocumentService documentService;

private List<String> fieldList = null;
private List<String> fieldListAnalyse = null;
private List<String> fieldListNoAnalyse = null;
private List<String> fieldListAnalyze = null;
private List<String> fieldListNoAnalyze = null;
private List<String> fieldListStore = null;
private Set<String> uniqueFieldList = null;

// default field lists
private static List<String> DEFAULT_SEARCH_FIELD_LIST = Arrays.asList("$workflowsummary", "$workflowabstract");
private static List<String> DEFAULT_NOANALYSE_FIELD_LIST = Arrays.asList("$modelversion", "$taskid", "$processid",
private static List<String> DEFAULT_NOANALYZE_FIELD_LIST = Arrays.asList("$modelversion", "$taskid", "$processid",
"$workitemid", "$uniqueidref", "type", "$writeaccess", "$modified", "$created", "namcreator", "$creator",
"$editor", "$lasteditor", "$workflowgroup", "$workflowstatus", "txtworkflowgroup", "name", "txtname",
"$owner", "namowner", "txtworkitemref", "$uniqueidsource", "$uniqueidversions", "$lasttask", "$lastevent",
Expand All @@ -124,8 +124,9 @@ public class SchemaService {
void init() {

logger.finest("......lucene FulltextFieldList=" + indexFields);
logger.finest("......lucene IndexFieldListAnalyse=" + indexFieldsAnalyse);
logger.finest("......lucene IndexFieldListNoAnalyse=" + indexFieldsNoAnalyse);
logger.finest("......lucene IndexFieldListAnalyze=" + indexFieldsAnalyze);
logger.finest("......lucene IndexFieldListNoAnalyze=" + indexFieldsNoAnalyze);
logger.finest("......lucene IndexFieldListStore=" + indexFieldsStore);

// compute search field list
fieldList = new ArrayList<String>();
Expand All @@ -143,30 +144,30 @@ void init() {
}

// compute Index field list (Analyze)
fieldListAnalyse = new ArrayList<String>();
if (indexFieldsAnalyse != null && !indexFieldsAnalyse.isEmpty()) {
StringTokenizer st = new StringTokenizer(indexFieldsAnalyse, ",");
fieldListAnalyze = new ArrayList<String>();
if (indexFieldsAnalyze != null && !indexFieldsAnalyze.isEmpty()) {
StringTokenizer st = new StringTokenizer(indexFieldsAnalyze, ",");
while (st.hasMoreElements()) {
String sName = st.nextToken().toLowerCase().trim();
// do not add internal fields
if (!"$uniqueid".equals(sName) && !"$readaccess".equals(sName)) {
fieldListAnalyse.add(sName);
fieldListAnalyze.add(sName);
}
}
}

// compute Index field list (NoAnalyze)
fieldListNoAnalyse = new ArrayList<String>();
fieldListNoAnalyze = new ArrayList<String>();
// add all static default field list
fieldListNoAnalyse.addAll(DEFAULT_NOANALYSE_FIELD_LIST);
if (indexFieldsNoAnalyse != null && !indexFieldsNoAnalyse.isEmpty()) {
fieldListNoAnalyze.addAll(DEFAULT_NOANALYZE_FIELD_LIST);
if (indexFieldsNoAnalyze != null && !indexFieldsNoAnalyze.isEmpty()) {
// add additional field list from imixs.properties
StringTokenizer st = new StringTokenizer(indexFieldsNoAnalyse, ",");
StringTokenizer st = new StringTokenizer(indexFieldsNoAnalyze, ",");
while (st.hasMoreElements()) {
String sName = st.nextToken().toLowerCase().trim();
// Issue #560 - avoid duplicates from indexFieldsAnalyse
if (!fieldListNoAnalyse.contains(sName) && !indexFieldsAnalyse.contains(sName)) {
fieldListNoAnalyse.add(sName);
// Issue #560 - avoid duplicates from indexFieldsAnalyze
if (!fieldListNoAnalyze.contains(sName) && !indexFieldsAnalyze.contains(sName)) {
fieldListNoAnalyze.add(sName);
}
}
}
Expand All @@ -187,13 +188,13 @@ void init() {

// Issue #518:
// if a field of the indexFieldListStore is not part of the
// fieldListAnalyse add not part of fieldListNoAnalyse , than we add these
// fields to the indexFieldListAnalyse. This is to guaranty that we store the
// fieldListAnalyze add not part of fieldListNoAnalyze , than we add these
// fields to the indexFieldListAnalyze. This is to guaranty that we store the
// field value in any case.
for (String fieldName : fieldListStore) {
if (!fieldListAnalyse.contains(fieldName) && !fieldListNoAnalyse.contains(fieldName)) {
// add this field into he indexFieldListAnalyse
fieldListAnalyse.add(fieldName);
if (!fieldListAnalyze.contains(fieldName) && !fieldListNoAnalyze.contains(fieldName)) {
// add this field into he indexFieldListAnalyze
fieldListAnalyze.add(fieldName);
}
}

Expand All @@ -202,8 +203,8 @@ void init() {
uniqueFieldList=new HashSet<String>();
uniqueFieldList.add(WorkflowKernel.UNIQUEID);
uniqueFieldList.addAll(fieldListStore);
uniqueFieldList.addAll(fieldListAnalyse);
uniqueFieldList.addAll(fieldListNoAnalyse);
uniqueFieldList.addAll(fieldListAnalyze);
uniqueFieldList.addAll(fieldListNoAnalyze);


}
Expand All @@ -224,8 +225,8 @@ public List<String> getFieldList() {
*
* @return
*/
public List<String> getFieldListAnalyse() {
return fieldListAnalyse;
public List<String> getFieldListAnalyze() {
return fieldListAnalyze;
}

/**
Expand All @@ -234,8 +235,8 @@ public List<String> getFieldListAnalyse() {
*
* @return
*/
public List<String> getFieldListNoAnalyse() {
return fieldListNoAnalyse;
public List<String> getFieldListNoAnalyze() {
return fieldListNoAnalyze;
}

/**
Expand Down Expand Up @@ -265,8 +266,8 @@ public ItemCollection getConfiguration() {
ItemCollection config = new ItemCollection();

config.replaceItemValue("lucence.fulltextFieldList", fieldList);
config.replaceItemValue("lucence.indexFieldListAnalyze", fieldListAnalyse);
config.replaceItemValue("lucence.indexFieldListNoAnalyze", fieldListNoAnalyse);
config.replaceItemValue("lucence.indexFieldListAnalyze", fieldListAnalyze);
config.replaceItemValue("lucence.indexFieldListNoAnalyze", fieldListNoAnalyze);
config.replaceItemValue("lucence.indexFieldListStore", fieldListStore);

return config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class LuceneIndexService {
public static final int EVENTLOG_ENTRY_FLUSH_COUNT = 16;

public static final String ANONYMOUS = "ANONYMOUS";
public static final String DEFAULT_ANALYSER = "org.apache.lucene.analysis.standard.ClassicAnalyzer";
public static final String DEFAULT_ANALYZER = "org.apache.lucene.analysis.standard.ClassicAnalyzer";
public static final String DEFAULT_INDEX_DIRECTORY = "imixs-workflow-index";

@PersistenceContext(unitName = "org.imixs.workflow.jpa")
Expand All @@ -98,8 +98,8 @@ public class LuceneIndexService {
private String luceneIndexDir;

@Inject
@ConfigProperty(name = "lucence.analyzerClass", defaultValue = DEFAULT_ANALYSER)
private String luceneAnalyserClass;
@ConfigProperty(name = "lucence.analyzerClass", defaultValue = DEFAULT_ANALYZER)
private String luceneAnalyzerClass;


@Inject
Expand Down Expand Up @@ -128,13 +128,13 @@ public void setLuceneIndexDir(String luceneIndexDir) {
}


public String getLuceneAnalyserClass() {
return luceneAnalyserClass;
public String getLuceneAnalyzerClass() {
return luceneAnalyzerClass;
}


public void setLuceneAnalyserClass(String luceneAnalyserClass) {
this.luceneAnalyserClass = luceneAnalyserClass;
public void setLuceneAnalyzerClass(String luceneAnalyzerClass) {
this.luceneAnalyzerClass = luceneAnalyzerClass;
}


Expand Down Expand Up @@ -419,16 +419,16 @@ protected Document createDocument(ItemCollection aworkitem) {
_localFieldListStore.addAll(schemaService.getFieldListStore());

// analyzed...
List<String> indexFieldListAnalyse = schemaService.getFieldListAnalyse();
for (String aFieldname : indexFieldListAnalyse) {
List<String> indexFieldListAnalyze = schemaService.getFieldListAnalyze();
for (String aFieldname : indexFieldListAnalyze) {
addItemValues(doc, aworkitem, aFieldname, true, _localFieldListStore.contains(aFieldname));
// avoid duplication.....
_localFieldListStore.remove(aFieldname);
}
// ... and not analyzed...

List<String> indexFieldListNoAnalyse = schemaService.getFieldListNoAnalyse();
for (String aFieldname : indexFieldListNoAnalyse) {
List<String> indexFieldListNoAnalyze = schemaService.getFieldListNoAnalyze();
for (String aFieldname : indexFieldListNoAnalyze) {
addItemValues(doc, aworkitem, aFieldname, false, _localFieldListStore.contains(aFieldname));
}

Expand Down Expand Up @@ -534,10 +534,10 @@ protected IndexWriter createIndexWriter() throws IOException {
// indexWriterConfig = new IndexWriterConfig(new ClassicAnalyzer());
try {
// issue #429
indexWriterConfig = new IndexWriterConfig((Analyzer) Class.forName(luceneAnalyserClass).newInstance());
indexWriterConfig = new IndexWriterConfig((Analyzer) Class.forName(luceneAnalyzerClass).newInstance());
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new IndexException(IndexException.INVALID_INDEX,
"Unable to create analyzer '" + luceneAnalyserClass + "'", e);
"Unable to create analyzer '" + luceneAnalyzerClass + "'", e);
}

return new IndexWriter(indexDir, indexWriterConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ IndexSearcher createIndexSearcher() throws IOException {
}

/**
* Returns in instance of a QueyParser based on a KeywordAnalyser. The method
* Returns in instance of a QueyParser based on a KeywordAnalyzer. The method
* set the lucene DefaultOperator to 'OR' if not specified otherwise in the
* imixs.properties.
*
Expand Down
Loading

0 comments on commit 0c2dda6

Please sign in to comment.