feat: 添加搜索功能
- 使用meilisearch进行搜索 - 增添搜索界面
This commit is contained in:
@ -63,9 +63,9 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { Search } from "@element-plus/icons-vue";
|
||||
import { MeiliSearch } from "meilisearch";
|
||||
|
||||
const router = useRouter();
|
||||
const localePath = useLocalePath();
|
||||
|
||||
const { setLocale } = useI18n();
|
||||
|
||||
@ -73,19 +73,16 @@ const searchQuery = ref("");
|
||||
|
||||
const activeName = ref<string | undefined>(undefined);
|
||||
|
||||
const handleSearch = async () => {
|
||||
if (searchQuery.value.trim()) {
|
||||
// 这里可以添加搜索逻辑,例如导航到搜索结果页面
|
||||
console.log("Searching for:", searchQuery.value);
|
||||
const meiliClient = new MeiliSearch({
|
||||
host: process.env.MEILI_HOST || "http://192.168.86.5:7700",
|
||||
});
|
||||
const index = meiliClient.index("production");
|
||||
const search = await index.search(searchQuery.value, {
|
||||
limit: 20,
|
||||
});
|
||||
console.log("Search results:", search.hits);
|
||||
}
|
||||
const handleSearch = () => {
|
||||
const trimmed = searchQuery.value.trim();
|
||||
if (!trimmed) return;
|
||||
navigateTo({
|
||||
path: localePath('/search'),
|
||||
query: {
|
||||
query: trimmed
|
||||
}
|
||||
})
|
||||
searchQuery.value = "";
|
||||
};
|
||||
|
||||
const refreshMenu = () => {
|
||||
|
||||
Reference in New Issue
Block a user