RE: Get the "title" field from the "assetentry" table

Dimas TB, modified 5 Years ago. New Member Posts: 2 Join Date: 3/27/20 Recent Posts
Hello!

I want to make a query to the "assetentry" table, which will get all those records whose "title" field contains the word "Shared". I tried to get it, but can't find the way.

AssetEntryQuery x = new AssetEntryQuery();
x.setTitle("Shared");
        
List<AssetEntry> title = AssetEntryLocalServiceUtil.getEntries(x);
        
for(int i=0; i<title.size(); i++) {
     System.out.println("Titulo " + i + ": " + title.get(i));
}

Thank you!

Regards!
thumbnail
Dominik Marks, modified 5 Years ago. Regular Member Posts: 149 Join Date: 8/29/12 Recent Posts
As far as I know there is no method to get Assets by title with a wildcard match.

Probably the best way to fulfil your requirement is to use Dynamic Queries: https://portal.liferay.dev/docs/7-2/appdev/-/knowledge_base/a/dynamic-query
Please note that asset title is multilanguage, so the field "title" contains an XML with all translations.
thumbnail
Christoph Rabel, modified 5 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
Maybe you could use Elasticsearch instead? I mean, ES has indexed all assets and writing a custom query isn't really hard. Maybe something along the following lines could work:
        SearchContext searchContext = new SearchContext();
        searchContext.setCompanyId(companyId);
        searchContext.setUserId(userId);
        searchContext.setGroupIds(groupIds);
        searchContext.setLocale(locale);
        BooleanQuery query = new BooleanQueryImpl();
        query.addTerm(Field.TITLE, keyword, true, BooleanClauseOccur.MUST);
// Add other filters to make the query more precise, e.g. to get rid of drafts and old versions:     criteriaBuilder.addExactRequiredTerm(query, "head", "true");        Hits hits = indexSearcherHelper.search(searchContext, query);