Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Brian Scott Schupbach
DynamicQuery to search JournalArticles by AssetCategory
April 13, 2012 1:30 PM
Answer

Brian Scott Schupbach

Rank: Expert

Posts: 329

Join Date: October 23, 2008

Recent Posts

I'm having the toughest time figuring this out and I am at a loss...it seems like this should work. Has anyone done anything similar or can point me in the right direction? here are a couple of variations that I've tried.

Thanks in advance.

Brian

1
2DynamicQuery query = DynamicQueryFactoryUtil.forClass(JournalArticle.class, PortalClassLoaderUtil.getClassLoader())
3                .add(PropertyFactoryUtil.forName(Field.GROUP_ID).eq(new Long(groupId).longValue()))
4.add(PropertyFactoryUtil.forName(Field.CATEGORY_ID).in(categoryIdArray))
5                .add(PropertyFactoryUtil.forName(Field.CATEGORY_ID).eq(tagId))
6                .addOrder(OrderFactoryUtil.desc(Field.CREATE_DATE));
7                query.setLimit(0, limit);


1
2DynamicQuery query = DynamicQueryFactoryUtil.forClass(JournalArticle.class, PortalClassLoaderUtil.getClassLoader())
3                .add(PropertyFactoryUtil.forName(Field.GROUP_ID).eq(new Long(groupId).longValue()))
4.add(PropertyFactoryUtil.forName(Field.CATEGORY_ID).eq(categoryId))
5                .add(PropertyFactoryUtil.forName(Field.CATEGORY_ID).eq(tagId))
6                .addOrder(OrderFactoryUtil.desc(Field.CREATE_DATE));
7                query.setLimit(0, limit);



1
2DynamicQuery query = DynamicQueryFactoryUtil.forClass(JournalArticle.class, PortalClassLoaderUtil.getClassLoader())
3                .add(PropertyFactoryUtil.forName(Field.GROUP_ID).eq(new Long(groupId).longValue()))
4.add(PropertyFactoryUtil.forName("keyword").eq(categoryId))
5                .add(PropertyFactoryUtil.forName(Field.CATEGORY_ID).eq(tagId))
6                .addOrder(OrderFactoryUtil.desc(Field.CREATE_DATE));
7                query.setLimit(0, limit);


1
2DynamicQuery query = DynamicQueryFactoryUtil.forClass(JournalArticle.class, PortalClassLoaderUtil.getClassLoader())
3                .add(PropertyFactoryUtil.forName(Field.GROUP_ID).eq(new Long(groupId).longValue()))
4.add(PropertyFactoryUtil.forName("keyword").eq("assetCategoryId:"+categoryId))
5                .add(PropertyFactoryUtil.forName(Field.CATEGORY_ID).eq(tagId))
6                .addOrder(OrderFactoryUtil.desc(Field.CREATE_DATE));
7                query.setLimit(0, limit);
Jelmer Kuperus
RE: DynamicQuery to search JournalArticles by AssetCategory
April 14, 2012 6:55 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

Ok here's what's going on :

You are creating a dynamic query for the JournalArticle entity. Dynamic queries get transformed to sql queries that run against the database.

The fields you are adding as criteria however are not properties of the JournalArticle entiy. There is no JournalArticle.getCategoryId() method for instance

The Field object you are referencing, probably is com.liferay.portal.kernel.search.Field which lists files that are stored in the (by default) lucene search index and *not* the database.

You probably would want to use AssetEntryServiceUtil.getEntries(AssetEntryQuery) for this
Brian Scott Schupbach
RE: DynamicQuery to search JournalArticles by AssetCategory
April 16, 2012 9:32 AM
Answer

Brian Scott Schupbach

Rank: Expert

Posts: 329

Join Date: October 23, 2008

Recent Posts

Ahh..that was stupid of me. Thanks for pointing that out.

Brian