···3344 ("seek, and ye shall eat spinach" - My primary school teacher)
5566-This is a fast text search engine, intended for use with source
66+Zoekt is a text search engine intended for use with source
77code. (Pronunciation: roughly as you would pronounce "zooked" in English)
8899-**Note:** This is a [Sourcegraph](https://github.com/sourcegraph/zoekt) fork
1010-of [github.com/google/zoekt](https://github.com/google/zoekt). It is now the
1111-main maintained source of Zoekt.
1212-1313-# INSTRUCTIONS
1414-1515-## Downloading
1616-1717- go get github.com/sourcegraph/zoekt/
99+**Note:** This has been the maintained source for Zoekt since 2017, when it was forked from the
1010+original repository [github.com/google/zoekt](https://github.com/google/zoekt).
18111919-## Indexing
1212+## Background
20132121-### Directory
1414+Zoekt supports fast substring and regexp matching on source code, with a rich query language
1515+that includes boolean operators (and, or, not). It can search individual repositories, and search
1616+across many repositories in a large codebase. Zoekt ranks search results using a combination of code-related signals
1717+like whether the match is on a symbol. Because of its general design based on trigram indexing and syntactic
1818+parsing, it works well for a variety of programming languages.
22192323- go install github.com/sourcegraph/zoekt/cmd/zoekt-index
2424- $GOPATH/bin/zoekt-index .
2020+The two main ways to use the project are
2121+* Through individual commands, to index repositories and perform searches through Zoekt's [query language](doc/query_syntax.md)
2222+* Or, through the indexserver and webserver, which support syncing repositories from a code host and searching them through a web UI or API
25232626-### Git repository
2424+For more details on Zoekt's design, see the [docs directory](doc/).
27252828- go install github.com/sourcegraph/zoekt/cmd/zoekt-git-index
2929- $GOPATH/bin/zoekt-git-index -branches master,stable-1.4 -prefix origin/ .
2626+## Usage
30273131-### Repo repositories
2828+### Installation
32293333- go install github.com/sourcegraph/zoekt/cmd/zoekt-{repo-index,mirror-gitiles}
3434- zoekt-mirror-gitiles -dest ~/repos/ https://gfiber.googlesource.com
3535- zoekt-repo-index \
3636- -name gfiber \
3737- -base_url https://gfiber.googlesource.com/ \
3838- -manifest_repo ~/repos/gfiber.googlesource.com/manifests.git \
3939- -repo_cache ~/repos \
4040- -manifest_rev_prefix=refs/heads/ --rev_prefix= \
4141- master:default_unrestricted.xml
3030+ go get github.com/sourcegraph/zoekt/
42314343-## Searching
3232+**Note**: It is also recommended to install [Universal ctags](https://github.com/universal-ctags/ctags), as symbol
3333+information is a key signal in ranking search results. See [ctags.md](doc/ctags.md) for more information.
44344545-### Web interface
3535+### Command-based usage
46364747- go install github.com/sourcegraph/zoekt/cmd/zoekt-webserver
4848- $GOPATH/bin/zoekt-webserver -listen :6070
3737+Zoekt supports indexing and searching repositories on the command line. This is most helpful
3838+for simple local usage, or for testing and development.
49395050-### JSON API
4040+#### Indexing a local git repo
51415252-You can retrieve search results as JSON by sending a GET request to zoekt-webserver.
4242+ go install github.com/sourcegraph/zoekt/cmd/zoekt-git-index
4343+ $GOPATH/bin/zoekt-git-index -index ~/.zoekt /path/to/repo
53445454- curl --get \
5555- --url "http://localhost:6070/search" \
5656- --data-urlencode "q=ngram f:READ" \
5757- --data-urlencode "num=50" \
5858- --data-urlencode "format=json"
4545+#### Indexing a local directory (not git-specific)
59466060-The response data is a JSON object. You can refer to [web.ApiSearchResult](https://sourcegraph.com/github.com/sourcegraph/zoekt@6b1df4f8a3d7b34f13ba0cafd8e1a9b3fc728cf0/-/blob/web/api.go?L23:6&subtree=true) to learn about the structure of the object.
4747+ go install github.com/sourcegraph/zoekt/cmd/zoekt-index
4848+ $GOPATH/bin/zoekt-index -index ~/.zoekt /path/to/repo
61496262-### CLI
5050+#### Searching an index
63516452 go install github.com/sourcegraph/zoekt/cmd/zoekt
6565- $GOPATH/bin/zoekt 'ngram f:READ'
6666-6767-## Installation
6868-A more organized installation on a Linux server should use a systemd unit file,
6969-eg.
7070-7171- [Unit]
7272- Description=zoekt webserver
7373-7474- [Service]
7575- ExecStart=/zoekt/bin/zoekt-webserver -index /zoekt/index -listen :443 --ssl_cert /zoekt/etc/cert.pem --ssl_key /zoekt/etc/key.pem
7676- Restart=always
7777-7878- [Install]
7979- WantedBy=default.target
8080-5353+ $GOPATH/bin/zoekt 'hello'
5454+ $GOPATH/bin/zoekt 'hello file:README'
81558282-# SEARCH SERVICE
5656+### Zoekt services
83578484-Zoekt comes with a small service management program:
5858+Zoekt also contains an index server and web server to support larger-scale indexing and searching
5959+of remote repositories. The index server can be configured to periodically fetch and reindex repositories
6060+from a code host. The webserver can be configured to serve search results through a web UI or API.
85616262+#### Indexing a GitHub organization
6363+8664 go install github.com/sourcegraph/zoekt/cmd/zoekt-indexserver
87658888- cat << EOF > config.json
8989- [{"GithubUser": "username"},
9090- {"GithubOrg": "org"},
9191- {"GitilesURL": "https://gerrit.googlesource.com", "Name": "zoekt" }
9292- ]
9393- EOF
6666+ echo YOUR_GITHUB_TOKEN_HERE > token.txt
6767+ echo '[{"GitHubOrg": "apache", "CredentialPath": "token.txt"}]' > config.json
94689595- $GOPATH/bin/zoekt-indexserver -mirror_config config.json
9696-9797-This will mirror all repos under 'github.com/username', 'github.com/org', as
9898-well as the 'zoekt' repository. It will index the repositories.
6969+ $GOPATH/bin/zoekt-indexserver -mirror_config config.json -data_dir ~/.zoekt/
9970100100-It takes care of fetching and indexing new data and cleaning up logfiles.
7171+This will fetch all repos under 'github.com/apache', then index the repositories. The indexserver takes care of
7272+periodically fetching and indexing new data, and cleaning up logfiles. See [config.go](cmd/zoekt-indexserver/config.go)
7373+for more details on this configuration.
10174102102-The webserver can be started from a standard service management framework, such
103103-as systemd.
7575+#### Starting the web server
104767777+ go install github.com/sourcegraph/zoekt/cmd/zoekt-webserver
7878+ $GOPATH/bin/zoekt-webserver -index ~/.zoekt/
10579106106-# SYMBOL SEARCH
8080+This will start a web server with a simple search UI at http://localhost:6070. See the [uuery syntax docs](doc/query_syntax.md)
8181+for more details on the query language.
10782108108-It is recommended to install [Universal
109109-ctags](https://github.com/universal-ctags/ctags) to improve
110110-ranking. See [here](doc/ctags.md) for more information.
8383+If you start the web server with `-rpc`, it exposes a [simple JSON search API](doc/json-api.md) at `http://localhost:6070/search/api/search.
111848585+Finally, the web server exposes a gRPC API that supports [structured query objects](query/query.go) and advanced search options.
11286113113-# ACKNOWLEDGEMENTS
8787+## Acknowledgements
1148811589Thanks to Han-Wen Nienhuys for creating Zoekt. Thanks to Alexander Neubeck for
11690coming up with this idea, and helping Han-Wen Nienhuys flesh it out.
117117-118118-119119-# FORK DETAILS
120120-121121-Originally this fork contained some changes that do not make sense to upstream
122122-and or have not yet been upstreamed. However, this is now the defacto source
123123-for Zoekt. This section will remain for historical reasons and contains
124124-outdated information. It can be removed once the dust settles on moving from
125125-google/zoekt to sourcegraph/zoekt. Differences:
126126-127127-- [zoekt-sourcegraph-indexserver](cmd/zoekt-sourcegraph-indexserver/main.go)
128128- is a Sourcegraph specific command which indexes all enabled repositories on
129129- Sourcegraph, as well as keeping the indexes up to date.
130130-- We have exposed the API via
131131- [keegancsmith/rpc](https://github.com/keegancsmith/rpc) (a fork of `net/rpc`
132132- which supports cancellation).
133133-- Query primitive `BranchesRepos` to efficiently specify a set of repositories to
134134- search.
135135-- Allow empty shard directories on startup. Needed when starting a fresh
136136- instance which hasn't indexed anything yet.
137137-- We can return symbol/ctag data in results. Additionally we can run symbol regex queries.
138138-- We search shards in order of repo name and ignore shard ranking.
139139-- Other minor changes.
140140-141141-Assuming you have the gerrit upstream configured, a useful way to see what we
142142-changed is:
143143-144144-``` shellsession
145145-$ git diff gerrit/master -- ':(exclude)vendor/' ':(exclude)Gopkg*'
146146-```
147147-148148-# DISCLAIMER
149149-150150-This is not an official Google product
+1-1
api.go
···1212// See the License for the specific language governing permissions and
1313// limitations under the License.
14141515-package zoekt // import "github.com/sourcegraph/zoekt"
1515+package zoekt
16161717import (
1818 "context"
doc/api.md
doc/json-api.md
+2
doc/query_syntax.md
···2233This guide explains the Zoekt query language, used for searching text within Git repositories. Zoekt queries allow combining multiple filters and expressions using logical operators, negations, and grouping. Here's how to craft queries effectively.
4455+For a brief overview of Zoekt's query syntax, see [these great docs from neogrok](https://neogrok-demo-web.fly.dev/syntax).
66+57---
6879## Syntax Overview