Customized Advanced search is not working when using AND & OR logical operators together.
I have a query regarding the customization of Advanced search..
After adding some of the custom attributes, logical operator based advanced search (i.e. using AND and OR operators) is not working.
Attaching herewith some piece of customized code. Actual customization is written in getNewRootExpression() method and because of which my advanced search (using AND and OR operators) is not working.
Can anybody pl. help me regarding this.
===============
protected void initSearch(ArgumentList args) {
// let the base class initialize the query
super.initSearch(args);
// Get the search string
String searchStr = getSearchInfo().getQueryDescription();
/* As simple search is change to a DQL query, On the search result page in place of search string "Complex DQL Query"
pharas is displaying. Additional argument is passed to replace the pharas to the search string value
*/
if((null != searchStr) && (searchStr.trim().length() != 0) && searchStr.trim().equals("Complex DQL Query")){
String strSearchString = args.get("searchString");
if(null != strSearchString)
getSearchInfo().setQueryDescription(strSearchString);
}
String strQueryType = args.get("queryType");
// Check if the search string is not null and is not an empty string
if ( (null != searchStr) && (searchStr.trim().length() != 0) && !"dql".equals(strQueryType)) {
try {
// Add an implicit trailing wildcard '*' to the search term
addImplicitWildcard(getSearchInfo().getQueryDescription());
} catch (Exception ex) {
LOGGER_.error("Error encountered while adding implicit wildcard to the search term: " + ex.getMessage(), ex);
}
}
}
private void addImplicitWildcard(String searchTerm) throws Exception {
if (!isEncapsulatedInQuotes( searchTerm) ) {
LOGGER_.debug("Search term user inserted or looking for:"+searchTerm);
// ArrayList to hold individual words in the search term
ArrayList<String> searchTermTokens = new ArrayList<String>();
// Get the words in the search string that are not enclosed in double quotes
getWildCardCandidates(searchTerm, searchTermTokens);
// Covert the ArrayList into a single string
String searchTermEx = getAsAString(searchTermTokens);
LOGGER_.debug("Search term if modified programmatically:"+searchTermEx);
// Check if the original search term and the one where we added implicit wildcard are not the same
if (!searchTermEx.equals(searchTerm)) {
if(getSearchInfo().getQueryBuilder()!=null){
IDfExpressionSet rootExpression = getSearchInfo().getQueryBuilder().getRootExpressionSet();
rootExpression = getNewRootExpression(rootExpression, searchTermEx, searchTerm);
addExcludedCabinets(rootExpression, null);
getSearchInfo().getQueryBuilder().setRootExpressionSet(rootExpression);
}
} else {
// Since no word in the search needed implicit wildcard, we will add
// excluded cabinet expressions to the exisit root expression
if(getSearchInfo().getQueryBuilder()!=null){
addExcludedCabinets(getSearchInfo().getQueryBuilder().getRootExpressionSet(), null);
}
}
}
}
private IDfExpressionSet getNewRootExpression(IDfExpressionSet rootExpression, String searchTermEx, String searchTerm ) throws Exception {
int containsOperandCodeVal = 8;
IDfExpressionSet newRoot = getSearchInfo().getSearchService().newQueryMgr().newQueryBuilder().getRootExpressionSet();
LOGGER_.debug("rootExprnsett Logical Operator :-" + rootExpression.getLogicalOperator());
LOGGER_.debug("newRoot Logical Operator :-" + newRoot.getLogicalOperator());
IDfEnumeration enumer = rootExpression.getExpressions();
while (enumer.hasMoreElements()) {
IDfExpression tempExpression = (IDfExpression) enumer.nextElement();
if (tempExpression.getExpressionType() == IDfExpression.EXPR_TYPE_FULLTEXT) {
newRoot.addFullTextExpression( getConcatenatedSearchExpression(searchTerm, searchTermEx));
}
else if (tempExpression.getExpressionType() == IDfExpression.EXPR_TYPE_SET)
{
LOGGER_.debug("Condition for adding wildcard for selected attribute and operand..tempExpression value is :-"+tempExpression.getExpressionType());
IDfExpressionSet innerExpressionSet = (IDfExpressionSet) tempExpression;
IDfEnumeration expressionsEnum = innerExpressionSet.getExpressions();
while (expressionsEnum.hasMoreElements())
{
IDfExpression innerExpression = (IDfExpression) expressionsEnum.nextElement();
if (innerExpression.getExpressionType() == IDfExpression.EXPR_TYPE_SIMPLE_ATTR)
{
IDfSimpleAttrExpression simpleInnerAttrExpression = (IDfSimpleAttrExpression) innerExpression;
if(simpleInnerAttrExpression.getSearchOperationCode()==containsOperandCodeVal){
LOGGER_.debug("SimpleInnerAttrExprsn operation type is :-" + simpleInnerAttrExpression.getSearchOperation() + " ::Operation code :-" + simpleInnerAttrExpression.getSearchOperationCode());
LOGGER_.debug("Making Simple text expression if Contains operand is selected");
LOGGER_.debug("simpleInnerAttrExpression.getAttrName()"+simpleInnerAttrExpression.getAttrName());
LOGGER_.debug("simpleInnerAttrExpression.getValueDataType()"+simpleInnerAttrExpression.getValueDataType());
//Simple Expression for term like *test*
newRoot.addSimpleAttrExpression(simpleInnerAttrExpression.getAttrName(), simpleInnerAttrExpression.getValueDataType(), IDfSimpleAttrExpression.SEARCH_OP_CONTAINS, false, false,"*"+searchTermEx);
LOGGER_.debug("Manipulating Simple text expression as::--"+"*"+searchTermEx);
/* Simple Expression for term like (test) OR (test*)
newRoot.addSimpleAttrExpression(simpleInnerAttrExpression.getAttrName(), simpleInnerAttrExpression.getValueDataType(), IDfSimpleAttrExpression.SEARCH_OP_CONTAINS, false, false, getConcatenatedSearchExpression(searchTerm, searchTermEx));
*/
/*Full Expression for term like (test) OR (test*)
newRoot.addFullTextExpression( getConcatenatedSearchExpression(searchTerm, searchTermEx));
*/
}else{
LOGGER_.debug("Else condition satisfied no changes");
newRoot.addExpression(tempExpression);
}
}
}
}
else
{
LOGGER_.debug("Last Else condition satisfied no changes");
newRoot.addExpression(tempExpression);
}
}
return newRoot;
}
Categories
- All Categories
- 123 Developer Announcements
- 54 Articles
- 151 General Questions
- 148 Thrust Services
- 57 OpenText Hackathon
- 37 Developer Tools
- 20.6K Analytics
- 4.2K AppWorks
- 9K Extended ECM
- 918 Core Messaging
- 84 Digital Asset Management
- 9.4K Documentum
- 32 eDOCS
- 186 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management
- 8 XM Fax
- Follow Categories