Custom Entity Indexer In Liferay 7.4 DXP Q4

Mohamed Saleem, modified 1 Month ago.

Custom Entity Indexer In Liferay 7.4 DXP Q4

Junior Member Posts: 40 Join Date: 12/16/15 Recent Posts

Hi,

I have created a custom entity and added a search indexer for it. After deploying the module, I can see my custom entity listed under Control Panel → Search → Index Actions. When I perform a reindex, the corresponding method is called and works correctly. I have also verified that the indexer methods are triggered on add, update, and delete operations.

However, when I search for any product using the search bar, it doesn’t return any results.

Can anyone help me understand what might be causing this issue?

below are my classes

@Component(immediate = true, service = Indexer.class)

public class ProductsIndexer extends BaseIndexer<Products> {

public static final String CLASS_NAME = Products.class.getName();

 

public ProductsIndexer() {

setDefaultSelectedFieldNames("productName", Field.UID);

setPermissionAware(true);

setFilterSearch(true);

}

 

@Override

public boolean hasPermission(PermissionChecker permissionChecker, String entryClassName, long entryClassPK,

String actionId) throws Exception {

System.out.println("bool Value ----"+hasPermission(permissionChecker, entryClassName, entryClassPK, ActionKeys.VIEW));

return super.hasPermission(permissionChecker, entryClassName, entryClassPK, ActionKeys.VIEW);

}

 

@Override

public String getClassName() {

// TODO Auto-generated method stub

return CLASS_NAME;

}

 

@Override

protected void doDelete(Products object) throws Exception {

System.out.println("method invoked In");

deleteDocument(object.getCompanyId(), object.getPrimaryKey());

System.out.println("method invoked Last");

}

 

@Override

protected Document doGetDocument(Products object) throws Exception {

Document document = getBaseModelDocument(Products.class.getName(), object);

 

// Add column to be indexed

System.out.println("Method In---"+object);

document.addText("productName", object.getProductName());

/*

* document.addKeyword(Field.ENTRY_CLASS_NAME, getClassName());

* document.addKeyword(Field.ENTRY_CLASS_PK, object.getPrimaryKey());

*/

document.addKeyword(Field.UID, PortalUtil.getClassName(PortalUtil.getClassNameId(Products.class)) + "#" + object.getPrimaryKey());

 

return document;

}

 

@Override

protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletRequest portletRequest,

PortletResponse portletResponse) throws Exception {

Summary summary = createSummary(document);

System.out.println("summarysummary-----"+summary);

summary.setMaxContentLength(200);

return summary;

}

 

@Override

protected void doReindex(String className, long classPK) throws Exception {

Products products = ProductsLocalServiceUtil.getProducts(classPK);

doReindex(products);

 

}

 

@Override

protected void doReindex(String[] ids) throws Exception {

long companyId = GetterUtil.getLong(ids[0]);

for (Products product : ProductsLocalServiceUtil.getProductses(-1, -1)) {

if (CompanyThreadLocal.getCompanyId() == companyId) {

System.out.println(companyId + "----------CompanyId----" + CompanyThreadLocal.getCompanyId());

doReindex(product);

}

}

 

}

 

 

@Override

protected void doReindex(Products object) throws Exception {

Document document = getDocument(object);

System.out.println("print document ---->"+document);

indexWriterHelper.updateDocument(object.getCompanyId(), document);

 

}

 

@Reference

IndexWriterHelper indexWriterHelper;

 

}

 

 

@Component(

immediate = true,

property = "indexer.class.name=common.service.model.Products",

service = ModelDocumentContributor.class

)

public class ProductsDocumentContributor implements ModelDocumentContributor<Products> {

 

@Override

public void contribute(Document document, Products baseModel) {

document.addText("productName", baseModel.getProductName());

}

 

}

 

 

@Component(immediate = true, property = "indexer.class.name=common.service.model.Products", service = ModelIndexerWriterContributor.class)

public class ProductsIndexerWriterContributor implements ModelIndexerWriterContributor<Products> {

 

@Override

public void customize(BatchIndexingActionable batchIndexingActionable,

ModelIndexerWriterDocumentHelper modelIndexerWriterDocumentHelper) {

batchIndexingActionable.setPerformActionMethod((Products entity) -> {

Document document = modelIndexerWriterDocumentHelper.getDocument(entity);

batchIndexingActionable.addDocuments(document);

});

 

}

 

@Override

public BatchIndexingActionable getBatchIndexingActionable() {

return _batchIndexingHelper

.getBatchIndexingActionable(_productsLocalService.getIndexableActionableDynamicQuery());

}

 

@Override

public long getCompanyId(Products baseModel) {

// TODO Auto-generated method stub

return baseModel.getCompanyId();

}

 

@Reference

private DynamicQueryBatchIndexingActionableFactory _batchIndexingHelper;

 

@Reference

private ProductsLocalService _productsLocalService;

 

}

 

 

When i am searching Results are not coming.

 

 

Community
Company
Feedback