Rest Service to search for Documents based on Metadata

Do you want to create a native client or integrate with third party applications: webservices are the solution.
Forum rules
Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
Post Reply
pcpower99
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: Fri Oct 31, 2014 9:18 pm

Rest Service to search for Documents based on Metadata

Post by pcpower99 » Fri Oct 31, 2014 9:35 pm

Hi!
I'm interfacing a Delphi 6 App with OpenKM trought RESTful
I have some functions already working OK.
Now I want to implement a function to search Documents based on Metadata or property groups.
What Rest function should I use: http://demo.openkm.com/OpenKM/services/ ... arch/xxxxx
How shoud I send the params?
An example would be really appreciated. Not necessarily related to Delphi, just the params
Thanks in advance.
Marcelo.

jllort
Moderator
Moderator
Posts: 9447
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Rest Service to search for Documents based on Metadata

Post by jllort » Sat Nov 01, 2014 9:48 am

I think the best for you is looking source code, it's easy to understood:
https://sourceforge.net/p/openkm/code/H ... /endpoint/
this is the search class https://sourceforge.net/p/openkm/code/H ... rvice.java

And you should be interested in these two methods:

Code: Select all

@GET
@Path("/find")
// Default "domain" is "1" for documents.
public QueryResultList find(@QueryParam("content") String content, @QueryParam("name") String name,
@DefaultValue("1") @QueryParam("domain") int domain, @QueryParam("keyword") List<String> keywords,
@QueryParam("category") List<String> categories, @QueryParam("property") List<String> properties,
@QueryParam("author") String author, @QueryParam("mimeType") String mimeType,
@QueryParam("lastModifiedFrom") String lastModifiedFrom, @QueryParam("lastModifiedTo") String lastModifiedTo,
@QueryParam("mailSubject") String mailSubject, @QueryParam("mailFrom") String mailFrom, @QueryParam("mailTo") String mailTo,
@QueryParam("path") String path) throws GenericException { 

@GET
@Path("/findPaginated") 
public ResultSet findPaginated(@DefaultValue("0") @QueryParam("offset") int offset, @DefaultValue("10") @QueryParam("limit") int limit,
@QueryParam("content") String content, @QueryParam("name") String name, @DefaultValue("1") @QueryParam("domain") int domain,
@QueryParam("keyword") List<String> keywords, @QueryParam("category") List<String> categories,
@QueryParam("property") List<String> properties, @QueryParam("author") String author, @QueryParam("mimeType") String mimeType,
@QueryParam("lastModifiedFrom") String lastModifiedFrom, @QueryParam("lastModifiedTo") String lastModifiedTo,
@QueryParam("mailSubject") String mailSubject, @QueryParam("mailFrom") String mailFrom, @QueryParam("mailTo") String mailTo,
@QueryParam("path") String path) throws GenericException 
Some interesting parameters:
domain = 1; // look only for documents ( for looking folders should be value 3 = DOCUMENT | FOLDER -> take a look the class https://sourceforge.net/p/openkm/code/H ... arams.java )
properties = list of values like propertyKey=value ( for example okp:test.name=name), something like { "okp:test.name=name", "okp:test.mail=some@mail.com" }

The other parameters I think are clear.

Sorry for our documentation, we're working to get a newer next year, a realistic estimation is next april. We're not perfect and sometimes we make some mistakes, we've discovered was not so good idea doing documentation in actual way, anyway that helped us to think how we would like to get it.

log-out
Junior Boarder
Junior Boarder
Posts: 22
Joined: Wed May 24, 2017 2:51 pm

Re: Rest Service to search for Documents based on Metadata

Post by log-out » Fri Jun 23, 2017 7:17 am

Hi all,

I'm trying to use rest service to search documents by metadata, without success...

First, I try my search in the application, search page, "use advanced search", using these parameters:

Tab Advanced -> Path: "/okm:root/Documentos"
Tab Metadata -> Add Metadata Group -> "okp:si_pr.idg": "*56*" (because I want to search documents where "idg" property contains "56" value)

I press "Find" and OpenKM searches one document. It's ok.

So, for the webservice I buid this URL:

Code: Select all

http://192.168.0.100:8080/OpenKM/services/rest/search/find?path=/okm:root/Documentos&property='okp:si_pr.idg=*56*'
But OpenKM returns all documents in /okm:root/Documentos path! What's wrong?

jllort
Moderator
Moderator
Posts: 9447
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Rest Service to search for Documents based on Metadata

Post by jllort » Fri Jun 23, 2017 9:23 am

I do not like much the character you are using to enclouse the property value '
Also you might escape property value always, although in this case I think is not relevant.
Try with this url:

Code: Select all

http://192.168.0.100:8080/OpenKM/services/rest/search/find?path=/okm:root/Documentos&property=okp:si_pr.idg=*56*
Here some samples in our online demo, should be the same as community:

Code: Select all

https://demo.openkm.com/OpenKM/services/rest/search/find?name=fg*&property=okp:consulting.name=test
https://demo.openkm.com/OpenKM/services/rest/search/find?property=okp:consulting.name=test
I do not remember now, when you use path if it's recursive or only restricted to that folder ( I'm talking about community version, in professional there's an parameter recursive ).

Final suggestion, you can take a look at the internal implementation https://github.com/openkm/document-mana ... rvice.java and debug into to see what happens.

log-out
Junior Boarder
Junior Boarder
Posts: 22
Joined: Wed May 24, 2017 2:51 pm

Re: Rest Service to search for Documents based on Metadata

Post by log-out » Fri Jun 23, 2017 9:36 am

Hi, I just found the problem, and you're right: the property value is without ' enclosure.

In documentation you can see a sample with enclosures, so I suggest you to change it.

Thanks,

jllort
Moderator
Moderator
Posts: 9447
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Rest Service to search for Documents based on Metadata

Post by jllort » Sun Jun 25, 2017 3:33 pm

The samples in the document section link you have shared are based in curl. It does not mean will be exactly the same rather using link directly in browser or using library for remote http request.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest