留言板

Filter JournalArticle by related document extension

Antonio Cirillo,修改在8 年前。

Filter JournalArticle by related document extension

New Member 帖子: 11 加入日期: 15-7-22 最近的帖子
I developed a portlet that filter content by keyword , category and range date. I should add a field that filter by document extension, for example if I select "PDF" the system must give me back only the contents that have a pdf attached. How could I do?
Thanks
thumbnail
Bijan Vakili,修改在8 年前。

RE: Filter JournalArticle by related document extension

Expert 帖子: 375 加入日期: 09-3-10 最近的帖子
The metadata are stored in Index; so assuming you are hitting index; you can retrieve by querying the same:

DLFileEntryIndexer.java for 6.2GA4:
https://github.com/liferay/liferay-portal/blob/0f75db5b5c6a8a7c6b07295cc12acdf362bfb1b4/portal-impl/src/com/liferay/portlet/documentlibrary/util/DLFileEntryIndexer.java#L281

The code at link above shows what to do: to retrieve the metadata needed. If it's strictly filename, then it depends a bit: is title of entry set to filename? If so, then you can hit that in Index:
https://github.com/liferay/liferay-portal/blob/0f75db5b5c6a8a7c6b07295cc12acdf362bfb1b4/portal-impl/src/com/liferay/portlet/documentlibrary/util/DLFileEntryIndexer.java#L388
Antonio Cirillo,修改在8 年前。

RE: Filter JournalArticle by related document extension

New Member 帖子: 11 加入日期: 15-7-22 最近的帖子
Thanks but honestly I did not understand how. I have to try , for example , only the web content that have a pdf.
This is my code for search JournalArticle by fullText, categories and range date:

SearchContext searchContext = new SearchContext();
BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);
if(fullText != null){
			BooleanQuery fullTextQuery = BooleanQueryFactoryUtil.create(searchContext);
			fullTextQuery.addTerms(new String[]{Field.TITLE,Field.DESCRIPTION,Field.CONTENT}, keywords, true);
			fullQuery.add(fullTextQuery, BooleanClauseOccur.MUST);
		} 
if (assetCategoryIds != null) {
			BooleanQuery strutturaQuery = BooleanQueryFactoryUtil.create(searchContext);
			for (long tmp : assetCategoryIds) {
				System.out.println(tmp);
				strutturaQuery.addRequiredTerm("assetCategoryIds", String.valueOf(tmp));
			}
			fullQuery.add(strutturaQuery, BooleanClauseOccur.MUST);
		}
/* Default date from 2010 to 2015 */
BooleanQuery rangeDateQuery = BooleanQueryFactoryUtil.create(searchContext);
		rangeDateQuery.addRangeTerm(Field.MODIFIED_DATE, "20100101", "20500101");
		fullQuery.add(rangeDateQuery, BooleanClauseOccur.MUST);

searchContext.setLike(false);
		searchContext.setStart(0);
		searchContext.setEnd(Integer.MAX_VALUE);

Sort[] sorts = { SortFactoryUtil.getSort(JournalArticle.class, "displayDate", "desc") };
		searchContext.setSorts(sorts);
		Hits results = SearchEngineUtil.search(searchContext, fullQuery);
		
		List<journalarticle> articles = new ArrayList<journalarticle>();
		for (Document document : results.getDocs()) {
			
			String entryClassName = GetterUtil.getString(document.get(Field.ENTRY_CLASS_NAME));
			long classPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));
			if (entryClassName.equals(JournalArticle.class.getName())) {
				JournalArticle article = JournalArticleLocalServiceUtil.fetchLatestArticle(classPK, WorkflowConstants.STATUS_APPROVED, true);
				articles.add(article);
			}
		}</journalarticle></journalarticle>


files do not seem to be directly connected to the web content . How can I do to look trivially all files related to a specific article ? Therefore , how to search for articles that have an attached document and that document has a specific extension .
Thank you
thumbnail
Andew Jardine,修改在8 年前。

RE: Filter JournalArticle by related document extension

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
Hi Antonio,

When you created the Journal Article, did you specify the related assets (documents from the documents library for example) as part of it's definition? If you did then the relationship between the two is stored in the AssetEntry table. I have never looked that closely, but I don't think that the Asset Entries are placed into the search index.

The simplest solution is probably to use the results of your search and then use the AssetEntry* portion of the API to retrieves the entries for each of the results and then check the mime/type of the asset entry to check for a corresponding match (for your example it would be application/pdf).

I'm not intimately familiar with the AssetEntry API -- there may even already be a method to do that. If there isn't, you could create a service wrapper to provide a simple method call that contains all details of performing the action you need -- https://www.liferay.com/web/juan.fernandez/blog/-/blogs/liferay-wrapper-plugins
Antonio Cirillo,修改在8 年前。

RE: Filter JournalArticle by related document extension

New Member 帖子: 11 加入日期: 15-7-22 最近的帖子
Yes I've added document with related asset function in web content.
The problem is I don't find the relation between JournalArticle and Related Asset!
The table Journal Article.ResourcePrimKey have a relation with AssetEntry.EntryID
The article have an id that isn't connected with related asset emoticon
Antonio Cirillo,修改在8 年前。

RE: Filter JournalArticle by related document extension

New Member 帖子: 11 加入日期: 15-7-22 最近的帖子
I've found the relation...
How do I know what content related to a web content?
The relations are made in this way :
JournalArticle.resourcePrimKey = AssetEntry.classPK
AssetLink.entry1 = JournalArticle.entryID

The table has a column AssetLink "entry2" which refers to all content related to the column "entry1" .
For example : an article with entry1 = 20123 will correspond with one or more entry2 .
thumbnail
Andew Jardine,修改在8 年前。

RE: Filter JournalArticle by related document extension

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
Hi Antonio,

Sorry for teh delay in getting back to you. It's been a crazy week. There is a column in the AssetEnty table called classNameId. You'll find that the value in this table relates back to the ClassName_ table where the second column contains the canonical name of the class. Checking that table I can see that the JournalArticle object has a classNameId of 10109 -- so you can use that in your filtering perhaps?
Antonio Cirillo,修改在8 年前。

RE: Filter JournalArticle by related document extension

New Member 帖子: 11 加入日期: 15-7-22 最近的帖子
Thank you for your support! emoticon
I have another question but I don't know if is the case to open a dedicated post.

I developed a portlet spring with a web service that placing full-text, categories, file type and date range returns a list of journal article. The search result is a JSON. What is the easiest way for this to work fronted by? I saw that Liferay using faceted search. In my case, however, I should be created create two portlet, the first containing the filters (which interrogate my web service via ajax) and the second containing the search results (the web content)
is this the correct solution or should have done differently?
thumbnail
Andew Jardine,修改在8 年前。

RE: Filter JournalArticle by related document extension

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
There are always MANY options when it comes to portlet design -- and a lot of the time more than one is fine and it really comes down to a matter of opinion. To answer your quetion I think first consider the way the (federated) Search portlet that Liferay comes with works.

The portlet is render first with a window state of NORMAL. So that of course means that it occupies whatever space it has based on the column from the layout it sits in (what ever constraints the css imposes really). When you do a search and get the results page your URL is the same, but the portlets window state becomes MAXIMIZED. This means that if the portlet is on a page with several other portlets, the other portlets are still there, but hidden but the maximized state of the Search portlet. This solution is great, if all you want on the search results page is your search results, but if you want to show other portlets as well, then you really want the portlet to remain in NORMAL view (which you can achieve with a JSP hook).

Personally I think that you should have one portlet. The render logic for you portlet, in the portlet class, would check for your "search criteria". If it find some then it will do a search and pass the results. If it does not, then it will fall through. Your JSP should have similar logic -- render teh search bar of course, and then do a check for the presence of search results. So the flow would go like this.

1. Page is rendering.
2. Custom Search portlet starts to render.
3. Are their categories? or keywords? -- Yes -> Call service with criteria and place results in the renderRequest, No -> skip search and do whatever.
4. JSP compilation starts (top to bottom)
5. Render the search field (text field + call to action)
6. JSTL If -> pagecontext contains search results, add "page content" to show results. Else -> don't render anything else.

Because the search criteria and the search results are interdependent (they really need each other) it makes sense to try to keep those things together. You're unlikely to place search results on a page by iteself afterall.

As for the JSON -- Liferay uses that for passing configuration to the search handler to tell it how to add parameters to Lucene for queries and how to organize results. If it is easier for you to pass a List<XXX> that comes back from your SOAP call to the JSP, you can just do that and use a JSTL foreach loop to output the results. Or you could get super fancy and use an AUI data table with your JSON object as the data binding emoticon

Hope this helps.
Antonio Cirillo,修改在8 年前。

RE: Filter JournalArticle by related document extension

New Member 帖子: 11 加入日期: 15-7-22 最近的帖子
Thanks a lot. Your answer is really complete and accurate emoticon