Help! - Content search that returns partial content items

16 views
Skip to first unread message

John Cross

unread,
Aug 18, 2017, 3:46:17 AM8/18/17
to dotCMS User Group
Hello!

I know this is probably a very basic question but for the life of me I can't figure it out...

I want to do a content search via the rest api to get all items of the content type 'Press Release'. This I can do easy enough, but it returns the entire content item for each and I actually only need the Publish Date field.

So, how do I limit the content search to only return certain fields?

Here is the URL I am using which returns the full content items:


What does it need to change to?

Thanks!

John

Jason Tesser

unread,
Aug 18, 2017, 7:43:59 AM8/18/17
to dotCMS User Group

The rest api will return all fields. Of course u can just display what you want.


--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com.
To post to this group, send email to dot...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/0bae1eea-690f-47f6-ab0b-0188ea9d8534%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

John Cross

unread,
Aug 18, 2017, 8:21:11 AM8/18/17
to dotCMS User Group
My concern here is the overhead - I'm returning all fields for 200 or so articles just to get a list of dates...

Chris Falzone

unread,
Aug 18, 2017, 9:41:34 AM8/18/17
to dotCMS User Group
Not supported currently, but I would second that this would be a nice a improvement to the REST APIs in dotCMS. 
I would say that if the overhead is too much and causing issues for you, the solution would be to create your own REST Service as a plugin to return just what you need.  

Nathan Keiter

unread,
Aug 18, 2017, 9:41:48 AM8/18/17
to dot...@googlegroups.com

You could easily write your own RESTful api to return only the fields specified.

 

Add a URL param /include-fields/Article.publishDate

 

Intercept that in the options and then modify the output accordingly.

 

Nathan I. Keiter | Lead Network Applications Programmer | Benefits Advisory Council Member | I.D.E.A Council Member
Gettysburg College | Information Technology | DataSystems
Campus Box 2453 | 300 North Washington Street | Gettysburg, PA 17325
Phone: 717.337.6993

https://www.gettysburg.edu

Nathan Keiter

unread,
Aug 18, 2017, 12:26:45 PM8/18/17
to dot...@googlegroups.com

It literally only took about 15 minutes. J You’ll need at least 3.x to use the built-in REST core libraries.

 

4.0.1 -> https://github.com/nkeiter/generic-dotCMS-plugin-code-examples/tree/master/dotcms4.0.1/osgi/org.example.nkeiter.contentlet.rest.light

 

3.5.1 -> https://github.com/nkeiter/generic-dotCMS-plugin-code-examples/tree/master/dotcms3.5.1/osgi/org.example.nkeiter.contentlet.rest.light

 

Where the magic happens -> https://github.com/nkeiter/generic-dotCMS-plugin-code-examples/blob/master/dotcms4.0.1/osgi/org.example.nkeiter.contentlet.rest.light/src/main/java/org/example/nkeiter/contentlet/rest/light/service/ContentletRestServiceLight.java#L66-L69

 

4.0.1 Jar –> https://github.com/nkeiter/generic-dotCMS-plugin-code-examples/tree/master/dotcms4.0.1/osgi/org.example.nkeiter.contentlet.rest.light/build/libs

 

3.5.1 Jar -> https://github.com/nkeiter/generic-dotCMS-plugin-code-examples/tree/master/dotcms3.5.1/osgi/org.example.nkeiter.contentlet.rest.light/build/libs

 

Keep in mind you might have to be logged in (as usual) depending on Content Type permissions.

 

Tested using Advanced REST client (Chrome app)

 

 

Nathan I. Keiter | Lead Network Applications Programmer | Benefits Advisory Council Member | I.D.E.A Council Member
Gettysburg College | Information Technology | DataSystems
Campus Box 2453 | 300 North Washington Street | Gettysburg, PA 17325
Phone: 717.337.6993

https://www.gettysburg.edu

 

Nathan Keiter

unread,
Aug 18, 2017, 1:54:43 PM8/18/17
to dot...@googlegroups.com

Actually, it might work on 2.x now.  I had to get a little creative with it and I don’t have an environment to test this in.  You’ll probably have to update your exported packages list in the OSGI admin panel to get this to work.

 

2.5.4 -> https://github.com/nkeiter/generic-dotCMS-plugin-code-examples/tree/master/dotcms2.5.4/osgi/org.example.nkeiter.contentlet.rest.light

 

2.5.4 Jar -> https://github.com/nkeiter/generic-dotCMS-plugin-code-examples/tree/master/dotcms2.5.4/osgi/org.example.nkeiter.contentlet.rest.light/build/libs

John Cross

unread,
Aug 21, 2017, 3:42:43 AM8/21/17
to dotCMS User Group
Thanks all!

This has been very useful. I'm surprised that it doesn't come out of the box with dotCMS - I'll put it to them as a future enhancement...

John
Reply all
Reply to author
Forward
0 new messages