Wednesday, August 5, 2015

Fetch/Retrive a Document with its Metadata Programmatically in Liferay


In my previous blogs we see how to upload a file with metadata. Now its time to fetch all the data Programmatically .Before reading this blog you must know how to create metadata sets and document type for this you can read my previous blog Save Document with Metadata in Liferay

This can be done in 2 parts:-
  • First we have to create indexer Post Processor hook.
  • Secondly we create Portlet for fetching the data.
For this blog i am using liferay 6.1.

Before start just create Resume(metadata sets) and Resume Type(Document Types) as describe in my previous blog Save Document with Metadata in Liferay

So lets start this step by step:-





Step 1:-Create Indexer Hook
For creating indexer post processor hook you may refer my previous blog Indexer Post Processor Hook in Liferay . Here i just created indexer on DLFileEntry Class and apply indexing on experience.

liferay-hook.xml


ExperienceIndexer.java


Explanation:-


  • In the postProcessDocument method we just fetch the metadata experience and add this as a index with key YearOfExperience.This method is called each time when we add a Resume ie Document Type Resume Type.
  • In postProcessSearchQuery method we create a Boolean query and pass experience as a argument.This method is called by our portlet.




Step 2:-Create Portlet that Call Boolean Query
Just create a Liferay Project with MVC portlet in it.Inside the Jsp file paste this content:-

view.jsp
And in your controller paste this content:-

Demo.java

Explanation:-
Here when we create SearchContext Object and set the attribute experience in it.This will automatically call the postProcessSearchQuery method of indexer and get the result on the basis of Experience. 

Step 3:-Check the output
Just create a folder and set the document type as "Resume type" as explained in my previous blog and add some document and provide experience as 4.5 or 3.0 etc.Now deploy your portlet and see the output as:-




When  you hit submit see the console :-






Hope this will Help....

You can Download Source code from  Fetch a Document with Metadata Programmatically in Liferay.


Related Post:-

No comments:

Post a Comment

Total Pageviews

Like Us on Facebook

Number Of Unique Visitor

Free counters!