Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

IQueryExpression Issue in KM Java

When building a KM query using the IQueryExpression and IQueryBuilder objects, we find we cannot "and" expressions together. Only the first expression is included in the query. We take three items as input from a Web Dynpro screen, verify that they are not null, and build as many as three separate IQueryExpression Objects, adding them to that which will actually be executed.

As stated earlier, only the first is actually added - what are we missing?

IResourceFactory resFact = ResourceFactory.getInstance();

ICollection coll = (ICollection) resFact.getResource("/documents/myRepository", resCtx);

IRepositoryManager repositoryMgr = coll.getRepositoryManager();

IPropertySearchManager searchMgr = repositoryMgr.getPropertySearchManager(coll);

IQueryBuilder queryBldr = searchMgr.getQueryBuilder();
IQueryExpression = null;

IPropertyName propNameA = new PropertyName("com.company", "PropA");
IPropertyName propNameB = new PropertyName("com.company", "PropB");
IPropertyName propNameC = new PropertyName("com.company", "PropC");

boolean searchIsBuilt = false;

String strPropA = wdContext.currentContextElement().getPropA();
strPropA = (strPropA == null) ? "" : strPropA.trim();

if (strPropA.length() > 0) {
    iQuery = queryBldr.eq(propNameA, strPropA);

    searchIsBuilt = true;

}

String strPropB = wdContext.currentContextElement().getPropB();
strPropB = (strPropB == null) ? "" : strPropB.trim();

if (strPropB.length() > 0) {
    if (searchIsBuilt) {
        IQueryExpression iq = queryBldr.eq(propNameB, strPropB);

        iQuery.and(iq);

    } else {
        iQuery = queryBldr.eq(propNameB, strPropB);

        searchIsBuilt = true;

    }

}

String strPropC = wdContext.currentContextElement().getPropC();
strPropC = (strPropC == null) ? "" : strPropC.trim();

if (strPropC.length() > 0) {
    if (searchIsBuilt) {
        IQueryExpression iq = queryBldr.likeIgnoreCase(propnameC, strPropC);

        iQuery.and(iq);

    } else {
        iQuery = queryBldr.likeIgnoreCase(propNameC, strPropC);

        searchIsBuilt = true;

    }

}

if (searchIsBuilt) {
    IResourceList result = searchMgr.execute(iQuery, coll, 0, 999, false);

    // Load context with results

} else {
   // Return message to the user - no parms entered

}

Former Member
Not what you were looking for? View more on this topic or Ask a question