This website uses cookies to ensure you get the best experience on our website.

Skip to content
LOGO
  • Company

    About IGNEK

    Learn about our story and our mission.

    Careers

    We're hiring!

    We always looking for talented peoples. Join our team!

    Blogs

    The latest industry news, updates and info.

    Case Studies

    Take a closer look at the projects we've delivered

    Webinar

    Watch our latest organized webinar

    Get in touch with our HR team

    • hr@ignek.com
    • +91 93284 95160
    • Ahmedabad, Gujarat, India – 382470
  • Services

    Enterprise Portal Development

    Custom Enterprise Portal Development for flawless Solutions

    Dedicated Development Team

    Expand Teams, Optimize Development with Our Expertise

    Back-end Development

    Empowering your digital presence with robust backend development expertise

    Front-end Development

    Crafting engaging user experiences through expert frontend development

    Digital Transformation

    Embrace digital transformation by modernizing process

    SaaS Development

    Transform your business with SaaS Innovative Solutions

    Technologies

    Liferay Services

    Development & Customization

    Theme

    Upgradation

    Migration

    Proof of Concept

    Performance Tunning

    Architecture

    Support & Maintenance

    E-commerce

    Expert Advice

    React Services

    Enterprise Development

    Custom Application

    Single Page Application

    Architecture

    API Integration

    Migration

    Consulting

    Maintenance & Support

    Spring Boot Services

    Web Service

    MVC Web Development

    API Integration

    Security

    Migration

    Microservices

    Support & Maintenance

    AEM Services

    Consulting Service

    Site Development

    Migration & Upgradation

    Integration

    Maintenance & Support

    Custom Solutions

    Content Management

    Team Augementation

  • Solution

    Ready for digital excellence

    In our rapidly evolving world, businesses are always on the lookout for fresh ways to improve their operations and connect with their audiences.

    Contact US

    Solutions

    SaaS : Software As A Service

    Transforming industries through cutting edge SaaS solutions.

    Customer Portal : Boost Business Productivity

    Streamline operations and enhance productivity with our Customer Portal solution.

    Liferay Based Intranet Portal

    Internal portal for company communication, collaboration and resources

    Integration

    Matomo Integration with Liferay

    Integrate Matomo to enable user interactions seamlessly.

    Microsoft Teams integration with Liferay

    Integrate to enable seamless collaboration, messaging within your portal.

    Jira Integration With Liferay

    Optimizes business operations by integrating with Jira.

  • Hire Us

    Liferay

    Get expert Liferay developers for seamless portal solutions.

    React JS

    Get expert ReactJS developers for dynamic web solutions.

    Web Developer

    Get custom web solutions from IGNEK's expert developers.

    Spring Boot

    Get top-notch Spring Boot developers for your project success!

    Healthcare

    Get top Healthcare Developers for cutting-edge medical software.

    MERN Stack

    Get expert MERN developers from IGNEK for custom, innovative project solutions.

    Why Hire Developers From IGNEK ?

    • Certified Developer
    • Transparent Communication
    • Flexible Hiring Modals
    • Fully Signed NDA
    • Cost Effective
    • Easy Exit Policy

    Get in touch with our Sales team

    • sales@ignek.com
    • +91 6351576580
    • info@ignek.com
    • Ahmedabad, Gujarat, India – 382470
SCHEDULE CALL
  • COMPANY
    • About
    • Case Studies
    • Blogs
    • Career
    • Webinar
  • SERVICES
    • Enterprise Portal Development
    • Dedicated Development Team
    • Back-end Development
    • Front-end Development
    • Digital Transformation
    • SaaS Development
  • SOLUTION
    • Customer Portal:  Boost Business Productivity
    • SaaS : Software as a Service
    • Liferay Based Employee Intranet Portal
  • TECHNOLOGY
    • Liferay Services
      • Liferay Development and Customization
      • Liferay Theme Development Service
      • Liferay DXP 7.4 Upgrade
      • Liferay Migration
      • Liferay Proof Of Concept
      • Liferay Performance Tuning
      • Liferay Architecture Design Service
      • Liferay Support And Maintenance Service
      • Liferay Ecommerce Development
      • Liferay Expert Advice
    • ReactJS Services
      • ReactJS Enterprise Application Development
      • ReactJS Custom Application Development
      • ReactJS Single Page Application Development (SPA)
      • ReactJS Applications Architecture
      • ReactJS API Integration
      • ReactJS Migration
      • ReactJS Consulting
      • ReactJS Maintenance and Support
    • Spring Boot Services
      • Spring Boot Web Development Service
      • Spring MVC Web Development
      • Spring Boot API Integration Service
      • Spring Boot Security
      • Spring Boot Migration Service
      • Spring Boot Microservices
      • Spring Boot Support & Maintenance Service
    • AEM Development Services
      • AEM Consulting Services
      • AEM Site Development
      • AEM Migration & Upgradation
      • AEM Integration Services
      • AEM Maintenance & Support
      • AEM Content Management
      • Custom AEM Solutions
      • AEM Team Augmentation
  • INTEGRATION
  • HIRE US
    • Hire Liferay Developer
    • Hire ReactJS Developer
    • Hire Spring Boot Developer
    • Hire Healthcare Developer
    • Hire Web Developer
    • Hire MERN Stack Developer
  • CONTACT US
  • Company

    About IGNEK

    Careers

    We're hiring!

    Blogs

    Case Studies

    Webinar

    Get in touch with our HR team

    • hr@ignek.com
    • +91 93284 95160
    • Ahmedabad, Gujarat, India – 382470
  • Services

    Enterprise Portal Development

    Dedicated Development Team

    Back-end Development

    Front-end Development

    Digital Transformation

    SaaS Development

    Technologies

    Liferay Liferay Services
    • Development & Customization
    • Theme
    • Upgradation
    • Migration
    • Proof of Concept
    • Performance Tuning
    • Architecture
    • Support & Maintenance
    • E-commerce
    • Expert Advice
    React React Services
    • Enterprise Development
    • Custom Application
    • Single Page Application
    • Architecture
    • API Integration
    • Migration
    • Consulting
    • Maintenance & Support
    Spring Boot Spring Boot Services
    • Web Service
    • MVC Web Development
    • API Integration
    • Security
    • Migration
    • Microservices
    • Support & Maintenance
    AEM AEM Services
    • Consulting Service
    • Site Development
    • Migration & Upgradation
    • Integration
    • Maintenance & Support
    • Custom Solutions
    • Content Management
    • Team Augmentation
  • Solution

    Ready for digital excellence

    In our rapidly evolving world, businesses are always on the lookout for fresh ways to improve their operations and connect with their audiences.

    Contact US

    Solutions

    SaaS : Software As A Service

    Customer Portal : Boost Business Productivity

    Liferay Based Intranet Portal

    Integration

    Matomo Integration with Liferay

    Microsoft Teams integration with Liferay

    Jira Integration With Liferay

  • Hire Us

    Liferay

    React JS

    Web Developer

    Spring Boot

    Healthcare

    MERN Stack

    Why Hire Developers From IGNEK ?

    • Certified Developer
    • Transparent Communication
    • Flexible Hiring Modals
    • Fully Signed NDA
    • Cost Effective
    • Easy Exit Policy

    Get in touch with our Sales team

    • sales@ignek.com
    • +91 6351576580
    • IGNEK
    • Ahmedabad, Gujarat, India – 382470
  • SCHEDULE CALL

Model Document Contributor in Liferay

  • Liferay
  • October 18, 2024

Share On :

Introduction

A Model Document Contributor in Liferay is essential for enhancing the search capabilities by allowing custom data from entities (models) to be indexed and made searchable in Liferay’s search engine (Elasticsearch).

Prerequisites
  • Liferay portal 7/7.x
  • Elasticsearch
Use of Model Document Contributor in Liferay
  • Out of the box, Liferay may not index all the fields of your custom entities. The Model Document Contributor allows you to define and include additional fields from your entities to be indexed, making them searchable.
  • By contributing specific data to the search index, you can ensure that relevant fields are available for search queries. This enhances the accuracy and relevance of search results.
  • It provides flexibility to control what data is indexed and how it is represented in the search index. 
  • When you have unique search requirements, such as custom filtering or sorting, the Model Document Contributor allows you to define how your custom model’s data should be indexed and retrieved.
  • In summary, the Model Document Contributor plays a vital role in extending and customizing the search functionality in Liferay, ensuring that your data is discoverable and that search results are tailored to your specific needs.
Creating Model Document Contributor in Liferay

For demonstration purposes, I created the web content structure below with three fields: Event Name, Start Date, and End Date. 

Structure

While creating web content with this structure, these three fields will not be indexed in Liferay’s search document by default. We will create a ModelDocumentContributor for the JournalArticle to index the Start Date in the document.

Please follow the below steps to create a model document contributor.

Step 1 : Create the service portlet.

  1. Open the Liferay workspace and create a new Liferay Module Project, and select ‘service’ in the Project Template Name.
  2. Provide the class name and package name and create the module.
Create_Module

Step 2 : Add ModelDocumetContributor to the service.

  1. Add the below line in the Component property.
				
					
indexer.class.name=com.liferay.journal.model.JournalArticle


				
			
  1. Provide service type as ‘ModelDocumentContributor.class’.
  2. Implement ‘ModelDocumentContributor<JournalArticle>’, and include the unimplemented methods.
Service_Declaration

Step 3 : Write the code in the contribute method.

				
					
package model.contributor;

import com.liferay.journal.model.JournalArticle;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.search.Document;
import com.liferay.portal.kernel.search.Field;
import com.liferay.portal.kernel.util.DateUtil;
import com.liferay.portal.kernel.xml.SAXReaderUtil;
import com.liferay.portal.search.spi.model.index.contributor.ModelDocumentContributor;
import java.util.Date;
import java.util.Locale;
import org.osgi.service.component.annotations.Component;

@Component(
	immediate = true,
	property = {
		 "indexer.class.name=com.liferay.journal.model.JournalArticle"
	},
	service = ModelDocumentContributor.class
)
public class JournalArticleModelDocumentContributor implements ModelDocumentContributor<JournalArticle> {
	
	private static final Log _log = LogFactoryUtil.getLog(JournalArticleModelDocumentContributor.class.getName());
	
	@Override
	public void contribute(Document document, JournalArticle journalArticle) {
		_log.info("Indexing " + journalArticle.getTitle(journalArticle.getDefaultLanguageId()));
		try {
			if(journalArticle.getDDMStructure().getStructureKey().equalsIgnoreCase("EVENT")) {
				com.liferay.portal.kernel.xml.Document saxDocument = SAXReaderUtil.read(journalArticle.getContent());
				String startDateStr = saxDocument.valueOf("//dynamic-element[@name='Date12018025']/dynamic-content/text()");
				try {
                    Date startDate = DateUtil.parseDate("yyyy-MM-dd", startDateStr, new Locale(journalArticle.getDefaultLanguageId()));
                    document.addDate("startDate", startDate);
                    document.addDateSortable(Field.getSortableFieldName("startDate"), startDate);
                    _log.info("Indexed startDate");
                } catch (Exception e){
                	 _log.error(e);
                }
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}




				
			

Explanation of the code

If the structure key of the JournalArticle is ‘EVENT’, the Start Date field will be fetched from the Journal Article and added to the document. When you deploy this service module, the Start Date field will be also indexed while creating the web content.

Note : we need to execute reindexing for existing content, Once indexed, we can directly use this custom field for searches.

To use this indexed field, I have created a blueprint.

  • In the query settings tab, I selected “Web Content Article” as the asset type. 
  • In the configuration tab, under sort configuration, I have applied sorting by the custom field ‘startDate’ in descending order.
Sort_Configuration

When I use this blueprint on the search results page, the (web contents of the event type structure will be displayed in descending order based on the start date.

Search_Results
Conclusion

Incorporating ModelDocumentContributor in Liferay provides a powerful way to customize how web content structure fields are indexed and searched. By leveraging this feature, you can enhance the search experience by including custom fields, such as dates or other metadata, in your search results. This not only improves the accuracy and relevance of search results but also allows for more flexible sorting and filtering options. 

Explore Our Services

Discover how we can help your business thrive, whether you’re running a small startup, an SME, or a large enterprise. We’re here to understand your unique needs and goals, offering the expertise and resources to support your journey to success.

Stay informed about our Liferay services and updates by subscribing to our newsletter—just fill in the details below to subscribe.

Loading
Loading...

Related Blogs

April 24, 2023
REST Builder in Liferay Cover Image
REST Builder in Liferay 7.x
August 30, 2024
What Is Liferay Blueprint and How We Can Use It
What Is Liferay Blueprint and How We Can Use It?
Loading...

Featured Projects Portfolios

March 21, 2024
EPF Government Enterprise Website _ Multilingual, Access for Member, Employer, Corporate - New
EPF Government Enterprise Website : Multilingual, Access for Member, Employer, Corporate
June 19, 2024
Music License Management Portal _ Onboarding & Data Integrity
Music License Management Portal : Onboarding & Data Integrity

Digital Solutions for Your Business with IGNEK

4.9

5.0

5.0

5.0

LOGO

Making the world a better place through constructing elegant hierarchies

COMPANY

  • About
  • Career
  • Case Study
  • Blogs

SERVICES

  • Enterprise Portal Development
  • Dedicated Development Team
  • Back-end Development
  • Front-end Development
  • Digital Transformation
  • SaaS Development

HIRE US

  • Liferay
  • Spring Boot
  • ReactJS
  • Healthcare
  • MERN Stack
  • AEM

CONTACT

  • info@ignek.com
  • info@ignek.com
SALES
  • sales@ignek.com
  • (+91) 635 157 6580
CAREER
  • hr@ignek.com
  • (+91) 932 849 5160
  • E 910-912, Ganesh Glory 11, Jagatpur Road, SG Highway, Ahmedabad, Gujarat - 382470

© 2018-2025 IGNEK, Inc. All rights reserved

Linkedin Facebook X-twitter Instagram