Skip to Main Content

WebCenter Sites Query Content using API

duspondaAug 28 2012
Hi all,
I have created a asset called "TVLContent" and for this asset, I created 2 attributes: "Question" and "Answer".
I need to create a query search using API, to get any content where "Question" or "Answer" attribute contains "Why".
I'm using the line code below, for searching, but doesn't work.

-----Code
Session ses = SessionFactory.getSession();
Condition c1 =ConditionFactory.createCondition("Question", OpTypeEnum.LIKE, "%Why%");
Condition c2 =ConditionFactory.createCondition("Answer", OpTypeEnum.LIKE, "%Why%" );
Query query = new SimpleQuery( "TVLContent", "FAQs", c1.or(c2) , Arrays.asList("name", "id", "Question", "Answer"));
query.getProperties().setIsBasicSearch(true);
AssetDataManager mgr = (AssetDataManager) ses.getManager(AssetDataManager.class.getName());
List<Long> firstResults = new ArrayList<Long>();
for(AssetData data : mgr.read(query)) {
//read data, e.g. data.getAttributeData("Question").getData()
}
------Code

If I change the query condition to c1 only, the query works fine,
e.g. Query query = new SimpleQuery( "TVLContent", "FAQs", c1 , Arrays.asList("name", "id", "Question", "Answer"));

If I change the query condition to c2 only, the query works fine.
e.g. Query query = new SimpleQuery( "TVLContent", "FAQs", c2 , Arrays.asList("name", "id", "Question", "Answer"));

But when I create a new condition (c1.or(c2)) doesn't work.
e.g. Query query = new SimpleQuery( "TVLContent", "FAQs", c1.or(c2) , Arrays.asList("name", "id", "Question", "Answer"));

How to fix this?
What's the best way to create this query using API?

See below the attribute definition:

Name: Question
Attribute Type: text
Attribute Editor: TVLTextArea
TVLTextArea XML (
<?XML VERSION="1.0"?>
<!DOCTYPE PRESENTATIONOBJECT SYSTEM "presentationobject.dtd">
<PRESENTATIONOBJECT NAME="TEXTAREA">
<TEXTAREA WRAPSTYLE ="SOFT"></TEXTAREA >
</PRESENTATIONOBJECT>
)

Name: Answer
Attribute Type: text
Attribute Editor: TVLCKEditor
TVLCKEditor XML (
<?XML VERSION="1.0"?>
<!DOCTYPE PRESENTATIONOBJECT SYSTEM "presentationobject.dtd">
<PRESENTATIONOBJECT NAME="TEXTAREA">
<TEXTAREA WRAPSTYLE ="SOFT"></TEXTAREA >
</PRESENTATIONOBJECT>
}
Post Details
Locked due to inactivity on Sep 25 2012
Added on Aug 28 2012
0 comments
379 views