oracle / opengrok

OpenGrok is a fast and usable source code search and cross reference engine, written in Java
http://oracle.github.io/opengrok/
Other
4.34k stars 745 forks source link

REST API Multi-project query encoding #2781

Closed comand closed 5 years ago

comand commented 5 years ago

With OpenGrok 1.2.0, I'm having a difficult time limiting a query via the REST API to a set of projects. I can't find anything that indicates how the 'projects' parameter to /search should be encoded in the request URL. I have searched for examples, but I can't find any that search multiple projects in one request. If Apiary says anything about what the actual format of this parameter should be, I wasn't able to find it... it accepts any text in the project field, and encodes it, but it doesn't look like I get any results at all (are there multiple projects available to search in apiary?)

How can I encode the following web request to work with the REST API?

http://grok/search?project=beta&project=mainline&project=release&q=SearchTerm

Any pointers would be greatly appreciated.

vladak commented 5 years ago

It's the same encoding, e.g. http://grok/source/api/v1/search?full=SearchTerm&projects=beta&projects=mainline&projects=release

It's a bit confusing to specify the project list with multiple projects parameters. That stems from the definition of the SearchController endpoint:


    @GET
    @CorsEnable
    @Produces(MediaType.APPLICATION_JSON)
    public SearchResult search(
            @Context final HttpServletRequest req,
            @QueryParam("full") final String full,
            @QueryParam("def") final String def,
            @QueryParam("symbol") final String symbol,
            @QueryParam("path") final String path,
            @QueryParam("hist") final String hist,
            @QueryParam("type") final String type,
            @QueryParam("projects") final List<String> projects,
            @QueryParam("maxresults") @DefaultValue(MAX_RESULTS + "") final int maxResults,
            @QueryParam("start") @DefaultValue(0 + "") final int startDocIndex

Jersey will just decode multiple occurrences of projects parameter in the URL into the List.

comand commented 5 years ago

Thanks!