Forums de discussion

How to implement search functionality for custom portlet in liferay 7?

thumbnail
Abhishek Jain, modifié il y a 7 années.

How to implement search functionality for custom portlet in liferay 7?

Regular Member Publications: 226 Date d'inscription: 20/08/16 Publications récentes
I have created an entity named Slogan. I want to add search functionality to this entity. For this I wrote following code :-
SearchContext searchContext = SearchContextFactory.getInstance(PortalUtil.getHttpServletRequest(req));
searchContext.setKeywords("a");
searchContext.setStart(0);
searchContext.setEnd(100);
Indexer indexer = IndexerRegistryUtil.getIndexer(Slogan.class);
Hits results = null;
try {
results = indexer.search(searchContext);
} catch (SearchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Document[] docs = results.getDocs();
System.out.println("length is "+docs.length);


But here I am getting NullPointerException as the value for results is null. It means indexer.search() is returning null. Any idea how to remove this error and bring the search functionality in the portlet successfully. Please help..thanx in advance..
thumbnail
Mohammad Azharuddin, modifié il y a 7 années.

RE: How to implement search functionality for custom portlet in liferay 7?

Expert Publications: 492 Date d'inscription: 17/09/12 Publications récentes
why cant you use finder method or dynamic query to filter the results
thumbnail
Abhishek Jain, modifié il y a 7 années.

RE: How to implement search functionality for custom portlet in liferay 7?

Regular Member Publications: 226 Date d'inscription: 20/08/16 Publications récentes
I tried with dynamic query but I got an error-java.lang.ClassNotFoundException: com.example.model.impl.SloganImpl. And this class is present in the jar andI included its dependency in the build.gradle and clicked on gradle->Refresh gradle. But then too, problem persists. Can you tell me how to eradicate it?
thumbnail
Mohammad Azharuddin, modifié il y a 7 années.

RE: How to implement search functionality for custom portlet in liferay 7?

Expert Publications: 492 Date d'inscription: 17/09/12 Publications récentes
Abhishek Jain:
I tried with dynamic query but I got an error-java.lang.ClassNotFoundException: com.example.model.impl.SloganImpl. And this class is present in the jar andI included its dependency in the build.gradle and clicked on gradle->Refresh gradle. But then too, problem persists. Can you tell me how to eradicate it?



Try adding both service modules inside your module

compile project(":modules:testing-services:testing-services-api")
compile project(":modules:testing-services:testing-services-service")

and select liferay workplace & cntl+f5
thumbnail
Abhishek Jain, modifié il y a 7 années.

RE: How to implement search functionality for custom portlet in liferay 7?

Regular Member Publications: 226 Date d'inscription: 20/08/16 Publications récentes
I already tried that but no success..now I changed the server and database but again NullPointerException with the code that I mentioned in my question!! Any sort of help would be appreciated..
thumbnail
Mohit Soni, modifié il y a 6 années.

RE: How to implement search functionality for custom portlet in liferay 7?

New Member Publications: 4 Date d'inscription: 02/01/14 Publications récentes
Can you share the code "how you are calling dynamic query?"
thumbnail
Denis Kipchakbaev, modifié il y a 6 années.

RE: How to implement search functionality for custom portlet in liferay 7?

New Member Publications: 9 Date d'inscription: 18/03/13 Publications récentes
Did you create an Indexer for your Slogan entity?