• 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.
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.
 #30404  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.
 #30412  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.
 #44154  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?
 #44158  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.
 #44163  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.

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.