Skip to content

Commit

Permalink
implementation search method
Browse files Browse the repository at this point in the history
Issue imixs#554
  • Loading branch information
rsoika committed Sep 1, 2019
1 parent bfc867e commit de02e90
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.logging.Logger;

Expand Down Expand Up @@ -96,6 +98,7 @@ public class SchemaService {
private List<String> fieldListAnalyse = null;
private List<String> fieldListNoAnalyse = 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");
Expand Down Expand Up @@ -192,6 +195,13 @@ void init() {
fieldListAnalyse.add(fieldName);
}
}


// build unique field list containing all field names
uniqueFieldList=new HashSet<String>();
uniqueFieldList.addAll(fieldListStore);
uniqueFieldList.addAll(fieldListAnalyse);
uniqueFieldList.addAll(fieldListNoAnalyse);

}

Expand Down Expand Up @@ -234,6 +244,15 @@ public List<String> getFieldListStore() {
return fieldListStore;
}

/**
* Returns a unique list of all fields part of the index schema.
* @return
*/
public Set<String> getUniqueFieldList() {
return uniqueFieldList;
}


/**
* Returns the Lucene schema configuration
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,48 +49,7 @@ public interface SearchService {
// number of hits
public static final int DEFAULT_PAGE_SIZE = 100; // default docs in one page

/**
* Returns a collection of documents matching the provided search term. The
* provided search team will we extended with a users roles to test the read
* access level of each workitem matching the search term.
*
* @param sSearchTerm
* @return collection of search result
* @throws QueryException
*/
//public List<ItemCollection> search(String sSearchTerm) throws QueryException;

/**
* Returns a collection of documents matching the provided search term. The
* provided search team will we extended with a users roles to test the read
* access level of each workitem matching the search term.
*
* @param pageSize
* - docs per page
* @param pageIndex
* - page number
*
* @return collection of search result
* @throws QueryException
*/
//public List<ItemCollection> search(String sSearchTerm, int pageSize, int pageIndex) throws QueryException;

/**
* Returns a collection of documents matching the provided search term. The term
* will be extended with the current users roles to test the read access level
* of each workitem matching the search term.
* <p>
* The method returns the full loaded documents. If you only want to search for
* document stubs use instead the method
* <p>
* <code>search(String searchTerm, int pageSize, int pageIndex, Sort sortOrder,
Operator defaultOperator, boolean loadStubs)</code>
* <p>
*
*/
// public List<ItemCollection> search(String sSearchTerm, int pageSize, int pageIndex, SortOrder sortOrder,
// DefaultOperator defaultOperator) throws QueryException;


/**
* Returns a collection of documents matching the provided search term. The term
* will be extended with the current users roles to test the read access level
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public class LuceneIndexService {
@PersistenceContext(unitName = "org.imixs.workflow.jpa")
private EntityManager manager;

private SimpleDateFormat luceneDateFormat=new SimpleDateFormat("yyyyMMddHHmmss");



@Inject
@ConfigProperty(name = "lucence.indexDir", defaultValue = DEFAULT_INDEX_DIRECTORY)
Expand Down Expand Up @@ -392,13 +395,12 @@ protected Document createDocument(ItemCollection aworkitem) {
continue;

if (o instanceof Calendar || o instanceof Date) {
SimpleDateFormat dateformat = new SimpleDateFormat("yyyyMMddHHmmss");
// convert calendar to string
String sDateValue;
if (o instanceof Calendar)
sDateValue = dateformat.format(((Calendar) o).getTime());
sDateValue = luceneDateFormat.format(((Calendar) o).getTime());
else
sDateValue = dateformat.format((Date) o);
sDateValue = luceneDateFormat.format((Date) o);
sValue += sDateValue + ",";

} else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ public class LuceneSearchService implements SearchService {


@Inject
@ConfigProperty(name = "lucene.defaultOperator", defaultValue = "AND")
@ConfigProperty(name = "index.defaultOperator", defaultValue = "AND")
private String luceneDefaultOperator;

@Inject
@ConfigProperty(name = "lucene.splitOnWhitespace", defaultValue = "true")
@ConfigProperty(name = "index.splitOnWhitespace", defaultValue = "true")
private boolean luceneSplitOnWhitespace;

@Inject
Expand All @@ -119,60 +119,7 @@ public class LuceneSearchService implements SearchService {

private static Logger logger = Logger.getLogger(LuceneSearchService.class.getName());

/**
* Returns a collection of documents matching the provided search term. The
* provided search team will we extended with a users roles to test the read
* access level of each workitem matching the search term.
*
* @param sSearchTerm
* @return collection of search result
* @throws QueryException
*/
// @Override
// public List<ItemCollection> search(String sSearchTerm) throws QueryException {
// // no sort order
// return search(sSearchTerm, DEFAULT_MAX_SEARCH_RESULT, 0, null, DefaultOperator.AND);
// }

/**
* Returns a collection of documents matching the provided search term. The
* provided search team will we extended with a users roles to test the read
* access level of each workitem matching the search term.
*
* @param pageSize
* - docs per page
* @param pageIndex
* - page number
*
* @return collection of search result
* @throws QueryException
*/
// @Override
// public List<ItemCollection> search(String sSearchTerm, int pageSize, int pageIndex) throws QueryException {
// // no sort order
// return search(sSearchTerm, pageSize, pageIndex, null, null);
// }

/**
* Returns a collection of documents matching the provided search term. The term
* will be extended with the current users roles to test the read access level
* of each workitem matching the search term.
* <p>
* The method returns the full loaded documents. If you only want to search for
* document stubs use instead the method
* <p>
* <code>search(String searchTerm, int pageSize, int pageIndex, Sort sortOrder,
Operator defaultOperator, boolean loadStubs)</code>
* <p>
*
*/
// @Override
// public List<ItemCollection> search(String sSearchTerm, int pageSize, int pageIndex,
// org.imixs.workflow.engine.index.SortOrder sortOrder, DefaultOperator defaultOperator)
// throws QueryException {
// return search(sSearchTerm, pageSize, pageIndex, sortOrder, defaultOperator, false);
// }


/**
* Returns a collection of documents matching the provided search term. The term
* will be extended with the current users roles to test the read access level
Expand Down Expand Up @@ -245,10 +192,10 @@ public List<ItemCollection> search(String searchTerm, int pageSize, int pageInde
parser.setAllowLeadingWildcard(true);

// set default operator?
if (defaultOperator == DefaultOperator.AND) {
parser.setDefaultOperator(org.apache.lucene.queryparser.classic.QueryParser.Operator.AND);
} else {
if (defaultOperator == DefaultOperator.OR) {
parser.setDefaultOperator(org.apache.lucene.queryparser.classic.QueryParser.Operator.OR);
} else {
parser.setDefaultOperator(org.apache.lucene.queryparser.classic.QueryParser.Operator.AND);
}

long lsearchtime = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@
*/
@Singleton
public class LuceneUpdateService implements UpdateService {



@Inject
private LuceneIndexService luceneIndexService;

Expand Down
Loading

0 comments on commit de02e90

Please sign in to comment.