掲示板

RE: How to get webcontents with specific tags using dynamic query.

11年前 に ruchi sharma によって更新されました。

How to get webcontents with specific tags using dynamic query.

Junior Member 投稿: 95 参加年月日: 11/03/24 最新の投稿
Hello Friends,

As in AssetEntryQuery we have a method
assetEntryQuery.setAllTagIds(assetTagIds);
using this method we can get the web contents having the some specific tags.
Due to some requirements I am using dynamic query not the AssetEntryQuery.
Just wondering how can I implement the same thing in dynamic query for getting the webcontents with specific tags.

Thanks
Ruchi
11年前 に ruchi sharma によって更新されました。

RE: How to get webcontents with specific tags using dynamic query.

Junior Member 投稿: 95 参加年月日: 11/03/24 最新の投稿
This is my dynamic query for retriving web contents between the two dates :
DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(AssetEntry.class, PortalClassLoaderUtil.getClassLoader());
Long[] testGroupId = ArrayUtil.toArray(groupIds);
dynamicQuery.add(PropertyFactoryUtil.forName("groupId").in(testGroupId));
Criterion criterion = null;
criterion = RestrictionsFactoryUtil.between("createDate", startDate, endDate);
dynamicQuery.add(criterion);
dynamicQuery.addOrder(OrderFactoryUtil.desc(orderByColumn1));
dynamicQuery.addOrder(OrderFactoryUtil.asc(orderByColumn2));
List<AssetEntry> results = AssetEntryLocalServiceUtil.dynamicQuery(dynamicQuery, scStart, scEnd);

Now I want to to add one more condition i.e webcontents with specific tags .
Any help would be appreciated.

Thanks
Ruchi
thumbnail
11年前 に Tejas Kanani によって更新されました。

RE: How to get webcontents with specific tags using dynamic query.

Liferay Master 投稿: 654 参加年月日: 09/01/06 最新の投稿
Hi Ruchi,

Not sure but check out below post. It might help you.

http://www.liferay.com/community/forums/-/message_boards/message/1817322#_19_message_1817471
thumbnail
11年前 に Prakash Khanchandani によって更新されました。

RE: How to get webcontents with specific tags using dynamic query.

Expert 投稿: 329 参加年月日: 11/02/10 最新の投稿
Immediate ways I can think of is to do this:

1) fetch the assetentries for the web-contents using AssetEntryQuery for specific tags.
2) prepare a list of IDs of classPK (this would be web-content IDs) from the assetEntries retrieved.
3) give the list of IDs to your dynamicQuery, something like this: dynamicQuery.in(list_of_webcontent_ids);

OR

1) try to create a dynamicquery with projection on classPK for fetching the assetEntries for particular tags
2) use this as a sub-query with your dynamicquery.

Example of how to use sub-queries:
1) Liferay forum
2) A blog

Hope this helps.
11年前 に Hiral Ramavat によって更新されました。

RE: How to get webcontents with specific tags using dynamic query.

Regular Member 投稿: 103 参加年月日: 12/02/13 最新の投稿
Hi,

You can not pass tag name directly to the argument to get the list of web content with specific tags.

It is the join query of journalarticle, tagasset, tagsassets_tagsentries and tagsentry tables.

First you need to get the tag id from the tagsentry table with specific tag name.
Then, get the assetId from the tagsassets_tagsentries which is the mapping table.
And map that assetId from the tagasset table to the journalarticle table. (journalarticle resourceprimKey is map to the ClassPK of the tagsasset)

Here this join query is regarding the Liferay 5.2.3.

Thanks,
Hiral
11年前 に ruchi sharma によって更新されました。

RE: How to get webcontents with specific tags using dynamic query.

Junior Member 投稿: 95 参加年月日: 11/03/24 最新の投稿
Thanks Tejas,Prakash and Hiral for your help.

After going through all your responses, I got an idea how to write the query.

1.getting the asset tag id from AssetTag table
DynamicQuery dynamicQueryTagId = DynamicQueryFactoryUtil.forClass(AssetTag.class, "assettag");
dynamicQueryTagId.setProjection(ProjectionFactoryUtil.property("assettag.classPK"));
dynamicQueryTagId.add(PropertyFactoryUtil.forName("assettag.name").in(tagNames));
List<AssetTag> assetTagsList = new ArrayList<AssetTag>();
assetTagsList = AssetTagLocalServiceUtil.dynamicQuery(dynamicQueryTagId);
2.Now I want to retrieve the entry id's from "assetentries_assettags" table which is the mapping table corresponding to the fetched tagid's list i.e assetTagsList .
here I am stuck how to get the entry ids coresponding to the tag ids, how to write the dynamic query for that.

3.Finally after getting the entry id's list I get the date from AssetEntry table.
This is what i am thinking for getting the webcontents with specific tags using dynamic query.
Thanks
Ruchi
11年前 に ruchi sharma によって更新されました。

RE: How to get webcontents with specific tags using dynamic query.

Junior Member 投稿: 95 参加年月日: 11/03/24 最新の投稿
Hello ,
How to make a join with AssetTag, AssetEntry and assetentries_assettags(mapping table) tables using a dynamicquery.
Is it possible??
Or do I need to use custom query??
Any help would be appreciated.
Thanks
Ruchi
11年前 に ruchi sharma によって更新されました。

RE: How to get webcontents with specific tags using dynamic query. (回答)

Junior Member 投稿: 95 参加年月日: 11/03/24 最新の投稿
Using custom query I solved my problem.
Thanks
Ruchi
thumbnail
10年前 に Habib Zare によって更新されました。

RE: How to get webcontents with specific tags using dynamic query.

Junior Member 投稿: 58 参加年月日: 12/10/28 最新の投稿
how?
9年前 に Javier Vera によって更新されました。

RE: How to get webcontents with specific tags using dynamic query.

New Member 投稿: 18 参加年月日: 14/08/01 最新の投稿
yop, i can imagine this is a very freaking late reply but then again..
if you have added tags to a custom service.xml and you want to list them all on your page so you can start figuring how to filter you can use the following queries..


	public List<assettag> _getTagsForClass() throws SystemException{
		long classNameId = PortalUtil.getClassNameId(<yourcustomclassinterface>.class.getName());
		DynamicQuery _queryT = DynamicQueryFactoryUtil.forClass(AssetEntry.class);
		_queryT.add(PropertyFactoryUtil.forName("classNameId").eq(classNameId));
		List<assettag> lstAssetTags = new ArrayList<assettag>();
		List<assetentry> lstAssetEntry = assetEntryLocalService.dynamicQuery(_queryT);
		//List<gmdcontent> lstFull = this._getAllMarketForRole(iUser);
		for (AssetEntry assetEntry : lstAssetEntry) {
			for (AssetTag assetTag : (AssetTagLocalServiceUtil.getEntryTags(assetEntry.getPrimaryKey()))) {
				if(!(lstAssetTags.stream().filter(obj -&gt; obj.getPrimaryKey() == assetTag.getPrimaryKey()).count() &gt; 0))
					lstAssetTags.add(assetTag);
			}
		}
		return lstAssetTags;	
	}
</gmdcontent></assetentry></assettag></assettag></yourcustomclassinterface></assettag>


if you have how to get stuff from the tag please reply. peace!