We are developing an enterprise application using ML as the document store. Large number of XML documents related to the business are store in the ML.
To implement the business logic, we need to have code where we retrieve XML by applying filter on them. Like: element_tag_1 = value1 && element_tag_2 > value2 || element_tag_3 = value2
Ex: emp_name = John && age > 40 || <available> != false
There are two parts here:
- The operators "||" and "&&" for logical grouping
- The operator >, <, = and != for comparison
Currently we are using the below code to generate the query and execute it. [The "emp_name" and Search text "John" are inserted programmatically. Not shown in snippet below]
StringBuilder sb = new StringBuilder();
sb.append("<search:search xmlns:search=\"http://marklogic.com/appservices/search\">");
sb.append(" <search:query>");
sb.append(" <search:value-query>");
sb.append(" <search:element name=\"emp_name\"/>");
sb.append(" <search:text>John</search:text>");
sb.append(" </search:value-query>");
sb.append(" </search:query>");
sb.append(" <search:options>");
sb.append(" <search:sort-order type=\"xs:string\" collation=\"http://marklogic.com/collation/\" direction=\"descending\">");
sb.append(" <search:element name=\"filterName\"/>");
sb.append(" </search:sort-order>");
sb.append(" </search:options>");
sb.append("</search:search>");
QueryManager queryMgr = client.newQueryManager();
SearchHandle resultsHandle = new SearchHandle();
RawQueryDefinition query = queryMgr.newRawCombinedQueryDefinition(new StringHandle(sb.toString()));
query.setCollections(BaseDataConstants.FILTER_COLLECTIONS);
queryMgr.search(query, resultsHandle);
Is the above approach correct?
Problem 1: With the above code we are only querying for emp_name = John on a document. How can we have multiple value-query with logical grouping between them like : emp_name = John && age > 40
Problem 2: Currently we are only doing = to comparison which is happening by default. How can we introduce operator here to check > , < and != in the value query.