Page 1 of 1

Rest Service to search for Documents based on Metadata

PostPosted:Fri Oct 31, 2014 9:35 pm
by pcpower99
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.

Re: Rest Service to search for Documents based on Metadata

PostPosted:Sat Nov 01, 2014 9:48 am
by jllort
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.

Re: Rest Service to search for Documents based on Metadata

PostPosted:Fri Jun 23, 2017 7:17 am
by log-out
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?

Re: Rest Service to search for Documents based on Metadata

PostPosted:Fri Jun 23, 2017 9:23 am
by jllort
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.

Re: Rest Service to search for Documents based on Metadata

PostPosted:Fri Jun 23, 2017 9:36 am
by log-out
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,

Re: Rest Service to search for Documents based on Metadata

PostPosted:Sun Jun 25, 2017 3:33 pm
by jllort
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.