go-gitea / gitea

Git with a cup of tea! Painless self-hosted all-in-one software development service, including Git hosting, code review, team collaboration, package registry and CI/CD
https://gitea.com
MIT License
43k stars 5.31k forks source link

REST API for Code Search #31375

Open kremerd opened 2 weeks ago

kremerd commented 2 weeks ago

Feature Description

One of Giteas best features is the blazing fast indexed full text search available at /explore/code. Unfortunately it seems that there is no REST API to access this feature programmatically. Such an API would be very useful to visualize results or present them in some other way.

Therefore I propose to introduce a new REST API

GET /api/v1/version/code?q=<queryString>&t=<fuzzy>&page=<pageNumber>&limit=<pageSize>

It should return a list of search results, containing at least the matched repository, file path, line number und line content

[{
    "repository": "my-repository",
    "path": "src/test/resources/strings.properties",
    "lineNumber": 255,
    "line": "TEXT=Lorem ipsum solor delet"
}]

Screenshots

No response

knudtty commented 4 days ago

I've put out a PR for this feature. It required refactoring the existing code search related modules in addition to adding new files for the api route. I decided to duplicate much of the web/explore/code.go function and adapt it for the API rather than a large refactor.