mirror of
https://github.com/tauri-apps/tauri-search.git
synced 2026-02-04 02:41:20 +01:00
chore: added CLI commands for creating and dropping indexes
This commit is contained in:
@@ -19,6 +19,7 @@ services:
|
||||
container_name: search
|
||||
ports:
|
||||
- 7700:7700
|
||||
- 2222:22
|
||||
volumes:
|
||||
- search_db:/home/db
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
"license": "MIT",
|
||||
"author": "Ken Snyder<ken@ken.net>",
|
||||
"scripts": {
|
||||
"cli:reset-index-config": "run-s cli:drop-indexes cli:create-indexes cli:push-caches",
|
||||
"cli:drop-indexes": "pnpm -C ./packages/tauri-search run drop-indexes",
|
||||
"cli:create-indexes": "pnpm -C ./packages/tauri-search run create-indexes",
|
||||
"cli:push-caches": "pnpm -C ./packages/tauri-search run push-caches",
|
||||
"cli:clear-caches": "pnpm -C ./packages/tauri-search run clear-caches",
|
||||
"clean": "pnpm run --filter ./packages run clean",
|
||||
|
||||
16
packages/docs/src/constants.ts
Normal file
16
packages/docs/src/constants.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export const SERVERS = [
|
||||
{
|
||||
default: true,
|
||||
name: "local",
|
||||
url: "http://localhost:7700",
|
||||
},
|
||||
{
|
||||
name: "prod",
|
||||
url: "https://search.tauri.com",
|
||||
indexes: [""],
|
||||
},
|
||||
{
|
||||
name: "pre-prod",
|
||||
url: "https://search2.tauri.com",
|
||||
},
|
||||
];
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { onStartTyping } from "@vueuse/core";
|
||||
import { useSearch } from "~/modules/search";
|
||||
import { SERVERS } from "~/constants";
|
||||
const el = ref();
|
||||
const s = useSearch();
|
||||
const searchText = ref(s.$state.searchQuery);
|
||||
@@ -28,7 +29,8 @@ onStartTyping(() => {
|
||||
</h1>
|
||||
<div class="grid grid-cols-3 gap-x-4">
|
||||
<div class="left">
|
||||
<!-- -->
|
||||
Server:
|
||||
<div v-for="server in SERVERS.map(i => i.name)" :key="server" class="server"></div>
|
||||
</div>
|
||||
|
||||
<div class="centered">
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
"clean": "rimraf dist/* bin/*",
|
||||
"clear-caches": "node bin/clear-caches.js",
|
||||
"create-indexes": "node bin/create-indexes.js",
|
||||
"drop-indexes": "node bin/drop-indexes.js",
|
||||
"current-indexes": "node bin/current-indexes.js",
|
||||
"lint": "eslint src --ext ts,js,tsx,jsx --fix --no-error-on-unmatched-pattern",
|
||||
"prune": "docker system prune",
|
||||
|
||||
9
packages/tauri-search/src/cli/drop-indexes.ts
Normal file
9
packages/tauri-search/src/cli/drop-indexes.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { ApiModel } from "../../dist";
|
||||
|
||||
async () => {
|
||||
const active = (await ApiModel.query.currentIndexes()).map((i) => i.name);
|
||||
console.log(`- clearing all active indexes: ${active.join(", ")}`);
|
||||
for (const idx of active) {
|
||||
ApiModel.query.deleteIndex(idx);
|
||||
}
|
||||
};
|
||||
@@ -9,15 +9,6 @@ export const TS_DOCS_CACHE = `src/generated/ast/api/ts-documents.json`;
|
||||
export const TS_AST_CACHE = `src/generated/ast/api/ts-ast.json`;
|
||||
export const RS_DOCS_CACHE = `src/generated/ast/api/rs-documents.json`;
|
||||
|
||||
const SERVERS = {
|
||||
local: {
|
||||
url: "http://localhost:7700",
|
||||
},
|
||||
production: {
|
||||
url: "https://search2.tauri.com",
|
||||
},
|
||||
};
|
||||
|
||||
export const REPOS: `${string}/${string}`[] = [
|
||||
"tauri-apps/tauri",
|
||||
"tauri-apps/wry",
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import { ModelMapper, isRepoDocument, isApiDocument } from "~/types";
|
||||
import { IApiModel, IConsolidatedModel, IProseModel, IRepoModel } from "~/models";
|
||||
|
||||
export enum IndexRank {
|
||||
prose = 5,
|
||||
repo = 3,
|
||||
api = 2,
|
||||
}
|
||||
|
||||
export const ConsolidatedMapper: ModelMapper<
|
||||
IApiModel | IRepoModel | IProseModel,
|
||||
IConsolidatedModel
|
||||
@@ -42,5 +48,10 @@ export const ConsolidatedMapper: ModelMapper<
|
||||
: i.code?.pop() || null,
|
||||
|
||||
content: isRepoDocument(i) ? i.text : isApiDocument(i) ? null : i.text,
|
||||
rank: isRepoDocument(i)
|
||||
? IndexRank.repo
|
||||
: isApiDocument(i)
|
||||
? IndexRank.api
|
||||
: IndexRank.prose,
|
||||
url: i.url,
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@ import { createModel } from "~/utils/createModel";
|
||||
|
||||
export type IConsolidatedModel = IScrapeSelectorTargets & {
|
||||
from: "prose" | "api" | "repo";
|
||||
rank: number;
|
||||
symbol: string | null;
|
||||
language: string | null;
|
||||
};
|
||||
@@ -18,4 +19,5 @@ export const ConsolidatedModel = createModel<IConsolidatedModel>("consolidated",
|
||||
javascript: ["ts", "typescript", "js"],
|
||||
})
|
||||
.filterable("from", "language", "symbol")
|
||||
.sortable("lvl0", "lvl3", "lvl2")
|
||||
);
|
||||
|
||||
@@ -20,21 +20,8 @@ export async function createIndexes() {
|
||||
const model = models[key as keyof typeof models];
|
||||
if (!skipping.includes(model.name)) {
|
||||
created.push(key);
|
||||
// create the index
|
||||
// create the index and configure it
|
||||
console.log(await model.query.createIndex());
|
||||
// then update settings
|
||||
const indexSettings: IMeilisearchIndexSettings<any> = {
|
||||
...(model.index.displayed ? { displayedAttributes: model.index.displayed } : {}),
|
||||
...(model.index.searchable
|
||||
? { searchableAttributes: model.index.searchable }
|
||||
: {}),
|
||||
...(model.index.filterable
|
||||
? { filterableAttributes: model.index.filterable }
|
||||
: {}),
|
||||
...(model.index.sortable ? { sortableAttributes: model.index.sortable } : {}),
|
||||
...(model.index.rules ? { rankingRules: model.index.rules } : {}),
|
||||
};
|
||||
await model.query.updateIndexSettings(indexSettings);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user