Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Charalampos Chrysikopoulos
Searching for JournalArticles with keywords and "AND" operator
June 6, 2012 7:03 AM
Answer

Charalampos Chrysikopoulos

Rank: New Member

Posts: 21

Join Date: December 8, 2011

Recent Posts

Hello,

i am trying to search for a group of articles using the method
 1
 2List<JournalArticle> results = JournalArticleLocalServiceUtil.search(
 3                themeDisplay.getCompanyId(),
 4                themeDisplay.getScopeGroupId(),
 5                0,
 6                null,
 7                null,
 8                null,
 9                "MY_STRUCTURE",
10                "MY_TEMPLATE",
11                startDateTime.toDate(), // startDate
12                endDateTime.toDate(), // endDate
13                0,
14                null,
15                QueryUtil.ALL_POS,
16                QueryUtil.ALL_POS,
17                null);


and this works fine, with an AND operator between all given values.
If I want to add some keywords (I have to search in the content, because I have a structure), then hard coded, the AND operator in the resulting SQL will change to a OR operator.

Is there a way to avoid this change? I need to filter my data in the SQL layer, so the keywords would be fine, only if there was also an AND operator.

Thank you in advance.
Charalampos Chrysikopoulos
RE: Searching for JournalArticles with keywords and "AND" operator
June 12, 2012 1:16 AM
Answer

Charalampos Chrysikopoulos

Rank: New Member

Posts: 21

Join Date: December 8, 2011

Recent Posts

The solution was easy enough:

There is another API call with has the boolean parameter for the AND operator but does not hat a keywords operator. In my case, because I want to search in the values of the structure of my WC, I can use the content parameter (which is also there in the new call).

So the new code looks like this:

 1
 2        List<JournalArticle> results = JournalArticleLocalServiceUtil.search(
 3                themeDisplay.getCompanyId(),
 4                themeDisplay.getScopeGroupId(),
 5                0,
 6                null, //articleId
 7                null, //version
 8                null, //title
 9                null, //description
10                content, // here you can put your keywords
11                null, // type
12                new String[] {"MY_STRUCTURE"},
13                new String[] {"MY_TEMPLATE"},
14                startDateTime.toDate(), // startDate
15                endDateTime.toDate(), // endDate
16                0,
17                null,
18                true, // andOperator
19                QueryUtil.ALL_POS,
20                QueryUtil.ALL_POS,
21                null);