【seafile】配置全文搜索

本文最后更新于:2022年11月4日 下午

Seafile 支持使用 ElasticSearch 服务实现全文搜索。

背景

搜索选项

可以在 seafevents.conf 中设置 [INDEX FILES] 选项来控制文件搜索的行为。你需要重新启动 seafileseahub 使它们生效。

1
vim /opt/seafile/data/seafile/conf/seafevents.conf

如果是跟着本博客做的,对于 pro 版,选择已经默认开启了全文搜索,可以跳过这小节。

默认配置如下:

1
2
3
4
5
6
7
8
9
10
11
12
[INDEX FILES]
external_es_server = true
es_host = elasticsearch
es_port = 9200
enabled = true
interval = 10m

highlight = fvh

## If true, indexes the contents of office/pdf files while updating search index
## Note: If you change this option from "false" to "true", then you need to clear the search index and update the index again. See the FAQ for details.
index_office_pdf = true

对于非pro版,如果没有开启,可以先按照下面的配置来进行修改:

1
2
3
4
5
6
7
8
9
10
[INDEX FILES]
## must be "true" to enable search
enabled = true

## The interval the search index is updated. Can be s(seconds), m(minutes), h(hours), d(days)
interval=10m

## If true, indexes the contents of office/pdf files while updating search index
## Note: If you change this option from "false" to "true", then you need to clear the search index and update the index again.
index_office_pdf=false

启用 Office/PDF 文件的全文搜索

全文搜索默认情况下不启用以保存系统资源,现在pro版是默认启用。如果要启用它,您需要按照以下说明进行操作。

首先,您必须在 seafevents.conf 中将 index_office_pdf 选项的值设置为 true

然后重新启动 seafile 服务,还需要删除现有的搜索索引并重建。

运行命令

【重要】对于docker运行网盘的时候

重新启动 seafile 服务。

1
docker exec -it seafile /opt/seafile/seafile-server-latest/reset-admin.sh/seafile.sh restart

删除现有的搜索索引并重建。

1
2
docker exec -it seafile /opt/seafile/seafile-server-latest/pro/pro.py search --clear
docker exec -it seafile /opt/seafile/seafile-server-latest/pro/pro.py search --update

对于非docker运行网盘

重新启动 seafile 服务。

1
2
cd /data/haiwen/seafile-pro-server-1.7.0/
./seafile.sh restart

删除现有的搜索索引并重建。

1
2
./pro/pro.py search --clear
./pro/pro.py search --update

常见问题

  1. 如果出现问题,请重建索引。

  2. 搜索关键字时,没有返回结果

    搜索索引默认每10分钟更新一次,所以在执行第一次搜索更新之前,无论你搜索什么都没有结果。

    为了能立即搜索:
    确保您已经启动 Seafile Server
    手动更新搜索索引

  3. 无法搜索加密文件
    服务器无法对加密文件进行索引,因为它们被加密了。

  4. 增加用于搜索的Java进程堆大小
    搜索功能基于Elasticsearch服务,这是一个Java进程。要增加Java堆内存大小,可以通过修改jvm配置文件来修改Elasticsearch使用的内存大小空间。例如,修改为2G内存空间。

    非docker运行:修改seafile-server-latest/pro/elasticsearch/config/jvm.options文件的以下配置项:

    1
    2
    3
    -Xms2g # 最小使用内存空间
    -Xmx2g # 最大使用内存空间
    ### 建议将以上两个配置项的值设置为一样大小。

docker-compose 运行:docker-compose.yml 文件中,

1
2
3
4
5
6
7
8
elasticsearch:
image: elasticsearch:7.16.2
container_name: seafile-elasticsearch
environment:
- discovery.type=single-node
- bootstrap.memory_lock=true
# 修改下面这行
- "ES_JAVA_OPTS=-Xms2g -Xmx2g"

重启seafile服务使上述修改生效:
非docker:
1
2
./seafile.sh restart
./seahub.sh restart

docker:
1
2
docker exec -it seafile /opt/seafile/seafile-server-latest/seafile.sh restart
docker exec -it seafile /opt/seafile/seafile-server-latest/seahub.sh restart


【seafile】配置全文搜索
https://pawswrite.xyz/posts/bdb7672.html
作者
Rainbow
发布于
2022年10月13日
许可协议