Forums de discussion

How to get webcontents with specific tags using dynamic query.

ruchi sharma, modifié il y a 11 années.

How to get webcontents with specific tags using dynamic query.

Junior Member Publications: 95 Date d'inscription: 24/03/11 Publications récentes
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
ruchi sharma, modifié il y a 11 années.

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

Junior Member Publications: 95 Date d'inscription: 24/03/11 Publications récentes
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
Tejas Kanani, modifié il y a 11 années.

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

Liferay Master Publications: 654 Date d'inscription: 06/01/09 Publications récentes
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
Prakash Khanchandani, modifié il y a 11 années.

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

Expert Publications: 329 Date d'inscription: 10/02/11 Publications récentes
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.
Hiral Ramavat, modifié il y a 11 années.

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

Regular Member Publications: 103 Date d'inscription: 13/02/12 Publications récentes
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
ruchi sharma, modifié il y a 11 années.

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

Junior Member Publications: 95 Date d'inscription: 24/03/11 Publications récentes
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
ruchi sharma, modifié il y a 11 années.

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

Junior Member Publications: 95 Date d'inscription: 24/03/11 Publications récentes
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
ruchi sharma, modifié il y a 11 années.

RE: How to get webcontents with specific tags using dynamic query. (Réponse)

Junior Member Publications: 95 Date d'inscription: 24/03/11 Publications récentes
Using custom query I solved my problem.
Thanks
Ruchi
thumbnail
Habib Zare, modifié il y a 11 années.

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

Junior Member Publications: 58 Date d'inscription: 28/10/12 Publications récentes
how?
Javier Vera, modifié il y a 9 années.

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

New Member Publications: 18 Date d'inscription: 01/08/14 Publications récentes
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!