Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Alex Curtui
Search for user Role
November 12, 2012 1:21 AM
Answer

Alex Curtui

Rank: Junior Member

Posts: 30

Join Date: November 8, 2012

Recent Posts

Hello,

Why can't I search Roles the way I search for Users?

 1        HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
 2        Indexer userIndexer = IndexerRegistryUtil.getIndexer([b]User[/b].class);
 3
 4        SearchContext searchContext = SearchContextFactory.getInstance(request);
 5
 6        searchContext.setGroupIds(null);
 7        searchContext.setKeywords(keyword);
 8
 9        Hits results = userIndexer.search(searchContext);
10
11        for (Document d : results.getDocs()){
12            //process user
13        }


If I replace the line
1Indexer userIndexer = IndexerRegistryUtil.getIndexer(User.class);

with
1Indexer userIndexer = IndexerRegistryUtil.getIndexer(Role.class);

it crashes.
Vitaliy Koshelenko
RE: Search for user Role
November 13, 2012 3:55 PM
Answer

Vitaliy Koshelenko

Rank: Regular Member

Posts: 240

Join Date: March 25, 2011

Recent Posts

Hi!
There is already user indexer implemented in Liferay ( com.liferay.portlet.enterpriseadmin.util.UserIndexer ), but there is no such one for roles.
Vitaliy
Alex Curtui
RE: Search for user Role
November 14, 2012 2:35 AM
Answer

Alex Curtui

Rank: Junior Member

Posts: 30

Join Date: November 8, 2012

Recent Posts

Thank you, I end up going for a different approach.
Roberto Díaz
RE: Search for user Role
November 14, 2012 5:11 AM
Answer

Roberto Díaz

LIFERAY STAFF

Rank: New Member

Posts: 24

Join Date: October 30, 2012

Recent Posts

You could use a hook to create a customized indexer

Maybe this link could help:

http://www.liferay.com/about-us/privacy/-/blogs/11643681/maximized