OpenGrok代码搜索引擎三OpenGrok常用命令

Posted 高桐@BILL

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OpenGrok代码搜索引擎三OpenGrok常用命令相关的知识,希望对你有一定的参考价值。

写在前面

        为了防止一些无法预料的情况发生,建议在完成代码项目索引创建后对索引生成器(indexer)生成的配置文件configuration.xml进行备份。

一、免配置方法

可以使用一个OpenGrok Docker容器,该容器包含了OpenGrok配置环境,但需要注意的是,该容器不适合大型的代码项目。

详细参考链接如下:

opengrok/docker at master · oracle/opengrok · GitHub

Docker Hub

二、常用命令

2.1 查看帮助

java -jar /opengrok/dist/lib/opengrok.jar -h

opengrok-indexer -a /opengrok/dist/lib/opengrok.jar -- -h

执行结果如下:

Apr 03, 2022 10:21:08 AM org.opengrok.indexer.index.Indexer parseOptions
INFO: Indexer options: [-h]

Usage: java -jar opengrok.jar [options] [subDir1 [...]]

  //帮助参数
  -h, -?, --help [mode]
        With no mode specified, display this usage summary. Or specify a mode:
          config - display configuration.xml examples.
           ctags - display ctags command-line.
            guru - display AnalyzerGuru details.
           repos - display enabled repositories.
  //设置同步API超时
  --apiTimeout number
        Set timeout for asynchronous API requests.

  //设置连接API超时
  --connectTimeout number
        Set connect timeout. Used for API requests.

  //设置分析器支持的格式,如拓展名,前缀等。
  -A, --analyzer (.ext|prefix.):(-|analyzer)
        Associates files with the specified prefix or extension (case-
        insensitive) to be analyzed with the given analyzer, where 'analyzer'
        may be specified using a class name (case-sensitive e.g. RubyAnalyzer)
        or analyzer language name (case-sensitive e.g. C). Option may be
        repeated.
          Ex: -A .foo:CAnalyzer
              will use the C analyzer for all files ending with .FOO
          Ex: -A bar.:Perl
              will use the Perl analyzer for all files starting with
              "BAR" (no full-stop)
          Ex: -A .c:-
              will disable specialized analyzers for all files ending with .c

  //指定ctags路径
  -c, --ctags /path/to/ctags
        Path to Universal Ctags. Default is ctags in environment PATH.

  //指定canonicalRoot路径
  --canonicalRoot /path/
        Allow symlinks to canonical targets starting with the specified root
        without otherwise needing to specify -N,--symlink for such symlinks. A
        canonical root must end with a file separator. For security, a canonical
        root cannot be the root directory. Option may be repeated.

  //检查索引
  --checkIndex
        Check index, exit with 0 on success,
        with 1 on failure.

  //指定OpenGrok数据生成的路径
  -d, --dataRoot /path/to/data/root
        The directory where OpenGrok stores the generated data.

  //指定代码仓扫描目录深度,默认为2
  --depth number
        Scanning depth for repositories in directory structure relative to
        source root. Default is 2.

  //不使能
  --disableRepository type_name
        Disables operation of an OpenGrok-supported repository. See also
        -h,--help repos. Option may be repeated.
          Ex: --disableRepository git
              will disable the GitRepository
          Ex: --disableRepository MercurialRepository

  //节省磁盘空间,OpenGrok不产生和保存超文本交叉引用文件等。
  -e, --economical
        To consume less disk space, OpenGrok will not generate and save
        hypertext cross-reference files but will generate on demand, which could
        be slightly slow.

  -G, --assignTags
        Assign commit tags to all entries in history for all repositories.

  //使能历史信息
  -H, --history
        Enable history.

  --historyThreads number
        The number of threads to use for history cache generation on repository level. By default                                                                                                         the number of threads will be set to the number of available CPUs.
        Assumes -H/--history.

  --historyFileThreads number
        The number of threads to use for history cache generation when dealing with individual fil                                                                                                        es.
        By default the number of threads will be set to the number of available CPUs.
        Assumes -H/--history.

  -I, --include pattern
        Only files matching this pattern will be examined. Pattern supports
        wildcards (example: -I '*.java' -I '*.c'). Option may be repeated.

  -i, --ignore pattern
        Ignore matching files (prefixed with 'f:' or no prefix) or directories
        (prefixed with 'd:'). Pattern supports wildcards (example: -i '*.so'
        -i d:'test*'). Option may be repeated.

  -l, --lock on|off|simple|native
        Set OpenGrok/Lucene locking mode of the Lucene database during index
        generation. "on" is an alias for "simple". Default is off.

  --leadingWildCards on|off
        Allow or disallow leading wildcards in a search. Default is on.

  -m, --memory number
        Amount of memory (MB) that may be used for buffering added documents and
        deletions before they are flushed to the directory (default 16.0).
        Please increase JVM heap accordingly too.

  --mandoc /path/to/mandoc
        Path to mandoc(1) binary.

  -N, --symlink /path/to/symlink
        Allow the symlink to be followed. Other symlinks targeting the same
        canonical target or canonical children will be allowed too. Option may
        be repeated. (By default only symlinks directly under the source root
        directory are allowed. See also --canonicalRoot)

  -n, --noIndex
        Do not generate indexes and other data (such as history cache and xref
        files), but process all other command line options.

  --nestingMaximum number
        Maximum depth of nested repositories. Default is 1.

  -O, --optimize on|off
        Turn on/off the optimization of the index database as part of the
        indexing step. Default is on.

  -o, --ctagOpts path
        File with extra command line options for ctags.

  -P, --projects
        Generate a project for each top-level directory in source root.

  -p, --defaultProject path/to/default/project
        Path (relative to the source root) to a project that should be selected
        by default in the web application (when no other project is set either
        in a cookie or in parameter). Option may be repeated to specify several
        projects. Use the special value __all__ to indicate all projects.

  --profiler
        Pause to await profiler or debugger.

  --progress
        Print per-project percentage progress information.

  -Q, --quickScan on|off
        Turn on/off quick context scan. By default, only the first 1024KB of a
        file is scanned, and a link ('[..all..]') is inserted when the file is
        bigger. Activating this may slow the server down. (Note: this setting
        only affects the web application.) Default is on.

  -q, --quiet
        Run as quietly as possible. Sets logging level to WARNING.

  -R /path/to/configuration
        Read configuration from the specified file.

  -r, --remote on|off|uionly|dirbased
        Specify support for remote SCM systems.
              on - allow retrieval for remote SCM systems.
             off - ignore SCM for remote systems.
          uionly - support remote SCM for user interface only.
        dirbased - allow retrieval during history index only for repositories
                   which allow getting history for directories.

  --renamedHistory on|off
        Enable or disable generating history for renamed files.
        If set to on, makes history indexing slower for repositories
        with lots of renamed files. Default is off.

  --repository [path/to/repository|@file_with_paths]
        Path (relative to the source root) to a repository for generating
        history (if -H,--history is on). By default all discovered repositories
        are history-eligible; using --repository limits to only those specified.
        File containing paths can be specified via @path syntax.
        Option may be repeated.

  -S, --search [path/to/repository|@file_with_paths]
        Search for source repositories under -s,--source, and add them. Path
        (relative to the source root) is optional.
        File containing paths can be specified via @path syntax.
        Option may be repeated.

  -s, --source /path/to/source/root
        The root directory of the source tree.

  --style path
        Path to the subdirectory in the web application containing the requested
        stylesheet. The factory-setting is: "default".

  -T, --threads number
        The number of threads to use for index generation, repository scan
        and repository invalidation.
        By default the number of threads will be set to the number of available
        CPUs. This influences the number of spawned ctags processes as well.

  -t, --tabSize number
        Default tab size to use (number of spaces per tab character).

  --token string|@file_with_string
        Authorization bearer API token to use when making API calls
        to the web application

  -U, --uri SCHEME://webappURI:port/contextPath
        Send the current configuration to the specified web application.

  --updateConfig
        Populate the web application with a bare configuration, and exit.

  --userPage URL
        Base URL of the user Information provider.
        Example: "https://www.example.org/viewProfile.jspa?username=".
        Use "none" to disable link.

  --userPageSuffix URL-suffix
        URL Suffix for the user Information provider. Default: "".

  -V, --version
        Print version, and quit.

  -v, --verbose
        Set logging level to INFO.

  -W, --writeConfig /path/to/configuration
        Write the current configuration to the specified file (so that the web
        application can use the same configuration).

  --webappCtags on|off
        Web application should run ctags when necessary. Default is off.

2.2 创建/更新索引

java \\
    -Djava.util.logging.config.file=/opengrok/etc/logging.properties \\
    -jar /opengrok/dist/lib/opengrok.jar \\
    -c /usr/local/bin/ctags \\
    -s /opengrok/src -d /opengrok/data -H -P -S -G \\
    -W /opengrok/etc/configuration.xml -U http://localhost:8080/source

或使用OpenGrok管理工具包中的opengrok-indexer

opengrok-indexer \\
    -J=-Djava.util.logging.config.file=/opengrok/etc/logging.properties \\
    -a /opengrok/dist/lib/opengrok.jar -- \\
    -c /usr/local/bin/ctags \\
    -s /opengrok/src -d /opengrok/data -H -P -S -G \\
    -W /opengrok/etc/configuration.xml -U http://localhost:8080/source

2.3 创建单个项目的索引或新增一个项目的索引

java \\
    -Djava.util.logging.config.file=/opengrok/etc/logging.properties \\
    -jar /opengrok/dist/lib/opengrok.jar \\
    -c /usr/local/bin/ctags \\
    -s /opengrok/src -d /opengrok/data -H -S -G -p /opengrok/src/06_systemd \\
    -W /opengrok/etc/configuration.xml -U http://localhost:8080/source

以上是关于OpenGrok代码搜索引擎三OpenGrok常用命令的主要内容,如果未能解决你的问题,请参考以下文章

OpenGrok代码搜索引擎四OpenGrok使用指南

如何限制对 OpenGrok 结果的访问?

请问lucene可以用来做日志分析和日志故障定位吗?

lucene翻译?(如何翻译如下语句?)

Lucene是啥?

各位大神,lucene分词后,怎么按着词频倒序排列