windows 啟動后
?
?
啟動成功后關鍵信息
Config file path: "none"
Database path: "./data.ms"
Server listening on: "http://localhost:7700"
Environment: "development"
Commit SHA: "0312fb22b8e660c939eaa24ebe44bae8e9e68b6a"
Commit date: "2025-07-17T15:57:39Z"
Package version: "1.16.0"
?瀏覽器訪問http://127.0.0.1:7700/
建立本地數據庫
Meilisearch 建立本地知識庫主要包括安裝啟動、創建索引、添加文檔等步驟,以下是詳細操作過程:
- 安裝 Meilisearch:
- 使用 Docker 安裝(推薦):打開終端,運行命令
docker pull getmeili/meilisearch:latest
拉取最新的 Meilisearch 鏡像。然后運行docker run -it --rm -p 7700:7700 -v d:/work/meilisearch/:/ getmeili/meilisearch:latest
啟動 Meilisearch 容器,其中-p 7700:7700
將容器的 7700 端口映射到本地的 7700 端口,-v d:/work/meilisearch/:/
用于掛載數據卷,可根據需要修改為合適的本地路徑。 - 使用 Homebrew 安裝(適用于 Mac):運行
brew update && brew install meilisearch
命令更新 Homebrew 并安裝 Meilisearch。安裝完成后,可以使用meilisearch --master-key={MASTER_KEY} --env production
命令啟動 Meilisearch,其中{MASTER_KEY}
需替換為你設置的主密鑰,--env production
表示以生產模式啟動,若不傳遞此參數,默認為開發模式。
- 使用 Docker 安裝(推薦):打開終端,運行命令
- 訪問管理界面:啟動成功后,打開瀏覽器,訪問
http://localhost:7700
,可以看到 Meilisearch 自帶的調試界面,用于后續的操作和調試。 - 創建索引:Meilisearch 中的索引類似于數據庫中的表,用于存儲文檔。你可以通過 API 或使用相應的 SDK 來創建索引。例如,使用 PHP SDK 時,代碼如下:
php
require_once __DIR__ . '/vendor/autoload.php';
use MeiliSearch\Client;
$client = new Client('http://localhost:7700');
$index = $client->index('your_index_name');
其中your_index_name
需替換為你想要創建的索引名稱。如果索引不存在,Meilisearch 會在第一次添加文檔時自動創建它。
4.?準備文檔數據:收集并整理你要添加到知識庫的文檔數據,確保數據格式符合 Meilisearch 的要求。通常文檔數據應為 JSON 格式的數組,每個元素是一個文檔對象,文檔對象中的字段名和字段值通過鍵值對的形式進行存儲。例如:
json
[{"id": 1, "title": "Document 1", "content": "This is the content of document 1."},{"id": 2, "title": "Document 2", "content": "This is the content of document 2."}
]
這里的id
字段通常作為主鍵,用于唯一標識每個文檔。
5.?添加文檔到索引:使用 API 或 SDK 將準備好的文檔數據添加到創建好的索引中。繼續以 PHP SDK 為例,代碼如下:
php
$documents = [{"id": 1, "title": "Document 1", "content": "This is the content of document 1."},{"id": 2, "title": "Document 2", "content": "This is the content of document 2."}
];
$index->addDocuments($documents);
執行上述代碼后,Meilisearch 會對文檔進行索引處理,使其可被搜索。
6.?搜索測試:回到 Meilisearch 的管理界面http://localhost:7700
,在搜索框中輸入關鍵詞,測試是否能夠正確搜索到添加的文檔。也可以通過 API 或 SDK 編寫搜索代碼來進行測試。
阿雪技術觀
在科技發展浪潮中,我們不妨積極投身技術共享。不滿足于做受益者,更要主動擔當貢獻者。無論是分享代碼、撰寫技術博客,還是參與開源項目維護改進,每一個微小舉動都可能蘊含推動技術進步的巨大能量。東方仙盟是匯聚力量的天地,我們攜手在此探索硅基生命,為科技進步添磚加瓦。
Hey folks, in this wild tech - driven world, why not dive headfirst into the whole tech - sharing scene? Don't just be the one reaping all the benefits; step up and be a contributor too. Whether you're tossing out your code snippets, hammering out some tech blogs, or getting your hands dirty with maintaining and sprucing up open - source projects, every little thing you do might just end up being a massive force that pushes tech forward. And guess what? The Eastern FairyAlliance is this awesome place where we all come together. We're gonna team up and explore the whole silicon - based life thing, and in the process, we'll be fueling the growth of technology. ?