@stacksjs/search-engine 0.57.3 โ 0.58.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/index.js +89 -0
- package/package.json +25 -22
- package/LICENSE.md +0 -21
- package/dist/drivers/index.d.ts +0 -1
- package/dist/drivers/index.mjs +0 -1
- package/dist/drivers/meilisearch.d.ts +0 -9
- package/dist/drivers/meilisearch.mjs +0 -23
- package/dist/helpers.d.ts +0 -95
- package/dist/helpers.mjs +0 -13
- package/dist/index.d.ts +0 -22
- package/dist/index.mjs +0 -49
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ The Stacks Search Engine is a unified driver system to easily interact with sear
|
|
|
20
20
|
## ๐ค Usage
|
|
21
21
|
|
|
22
22
|
```bash
|
|
23
|
-
|
|
23
|
+
bun install -d @stacksjs/search-engine
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
You may now use:
|
|
@@ -38,7 +38,7 @@ Learn more in the docs.
|
|
|
38
38
|
## ๐งช Testing
|
|
39
39
|
|
|
40
40
|
```bash
|
|
41
|
-
|
|
41
|
+
bun test
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
## ๐ Changelog
|
|
@@ -57,10 +57,10 @@ For help, discussion about best practices, or any other conversation that would
|
|
|
57
57
|
|
|
58
58
|
For casual chit-chat with others using this package:
|
|
59
59
|
|
|
60
|
-
[Join the Stacks Discord Server](https://discord.
|
|
60
|
+
[Join the Stacks Discord Server](https://discord.gg/stacksjs)
|
|
61
61
|
|
|
62
62
|
## ๐ License
|
|
63
63
|
|
|
64
64
|
The MIT License (MIT). Please see [LICENSE](https://github.com/stacksjs/stacks/tree/main/LICENSE.md) for more information.
|
|
65
65
|
|
|
66
|
-
Made with
|
|
66
|
+
Made with ๐
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/index.ts
|
|
3
|
+
import {searchEngine} from "@stacksjs/config";
|
|
4
|
+
import {useStorage} from "@stacksjs/utils";
|
|
5
|
+
|
|
6
|
+
// src/helpers.ts
|
|
7
|
+
function determineState() {
|
|
8
|
+
const ls = localStorage.getItem("search-engine");
|
|
9
|
+
if (isString(ls))
|
|
10
|
+
return JSON.parse(ls);
|
|
11
|
+
return {
|
|
12
|
+
source: "http://127.0.0.1:7700",
|
|
13
|
+
index: "",
|
|
14
|
+
perPage: 20,
|
|
15
|
+
currentPage: 1,
|
|
16
|
+
query: ""
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
function client() {
|
|
22
|
+
if (searchEngine.driver === "meilisearch")
|
|
23
|
+
return meilisearch;
|
|
24
|
+
}
|
|
25
|
+
function useSearchEngine() {
|
|
26
|
+
return client();
|
|
27
|
+
}
|
|
28
|
+
function calculatePagination() {
|
|
29
|
+
if (table.perPage)
|
|
30
|
+
totalPages.value = Math.ceil(totalHits / table.perPage);
|
|
31
|
+
const hitPages = [...Array(totalPages.value).keys()].map((i) => i + 1);
|
|
32
|
+
const offset = 2;
|
|
33
|
+
const currentPage = table.currentPage ?? 1;
|
|
34
|
+
const lastPage = hitPages[hitPages.length - 1];
|
|
35
|
+
let from = currentPage - offset;
|
|
36
|
+
if (from < 1)
|
|
37
|
+
from = 1;
|
|
38
|
+
let to = from + offset * 2;
|
|
39
|
+
if (to >= lastPage)
|
|
40
|
+
to = lastPage;
|
|
41
|
+
const allPages = [];
|
|
42
|
+
for (let page = from;page <= to; page++)
|
|
43
|
+
allPages.push(page);
|
|
44
|
+
pages.value = allPages;
|
|
45
|
+
}
|
|
46
|
+
var table = useStorage("table", determineState()).value;
|
|
47
|
+
var totalHits = table.results?.estimatedTotalHits ?? 1;
|
|
48
|
+
var pages = ref([]);
|
|
49
|
+
var totalPages = ref(0);
|
|
50
|
+
var currentPage = computed(() => table.currentPage);
|
|
51
|
+
var filterName = computed(() => table.filterName);
|
|
52
|
+
var filters = computed(() => table.filters);
|
|
53
|
+
var goToNextPage = computed(() => table.goToNextPage);
|
|
54
|
+
var goToPage = computed(() => table.goToPage);
|
|
55
|
+
var goToPrevPage = computed(() => table.goToPrevPage);
|
|
56
|
+
var hits = computed(() => table.hits);
|
|
57
|
+
var index = computed(() => table.index);
|
|
58
|
+
var lastPageNumber = computed(() => table.lastPageNumber);
|
|
59
|
+
var perPage = computed(() => table.perPage);
|
|
60
|
+
var query = computed(() => table.query);
|
|
61
|
+
var results = computed(() => table.results);
|
|
62
|
+
var searchFilters = computed(() => table.searchFilters);
|
|
63
|
+
var searchParams = computed(() => table.searchParams);
|
|
64
|
+
var setTotalHits = computed(() => table.setTotalHits);
|
|
65
|
+
var sort = computed(() => table.sort);
|
|
66
|
+
var sorts = computed(() => table.sorts);
|
|
67
|
+
export {
|
|
68
|
+
useSearchEngine,
|
|
69
|
+
totalPages,
|
|
70
|
+
sorts,
|
|
71
|
+
sort,
|
|
72
|
+
setTotalHits,
|
|
73
|
+
searchParams,
|
|
74
|
+
searchFilters,
|
|
75
|
+
results,
|
|
76
|
+
query,
|
|
77
|
+
perPage,
|
|
78
|
+
lastPageNumber,
|
|
79
|
+
index,
|
|
80
|
+
hits,
|
|
81
|
+
goToPrevPage,
|
|
82
|
+
goToPage,
|
|
83
|
+
goToNextPage,
|
|
84
|
+
filters,
|
|
85
|
+
filterName,
|
|
86
|
+
currentPage,
|
|
87
|
+
client,
|
|
88
|
+
calculatePagination
|
|
89
|
+
};
|
package/package.json
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/search-engine",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"packageManager": "pnpm@8.6.6",
|
|
4
|
+
"version": "0.58.19",
|
|
6
5
|
"description": "The Stacks search engine integrations.",
|
|
7
6
|
"author": "Chris Breuer",
|
|
8
7
|
"license": "MIT",
|
|
9
8
|
"funding": "https://github.com/sponsors/chrisbbreuer",
|
|
10
|
-
"homepage": "https://github.com/stacksjs/stacks/tree/main
|
|
9
|
+
"homepage": "https://github.com/stacksjs/stacks/tree/main/storage/framework/core/src/search-engine#readme",
|
|
11
10
|
"repository": {
|
|
12
11
|
"type": "git",
|
|
13
12
|
"url": "git+https://github.com/stacksjs/stacks.git",
|
|
14
|
-
"directory": "
|
|
13
|
+
"directory": "./storage/framework/core/src/search-engine"
|
|
15
14
|
},
|
|
16
15
|
"bugs": {
|
|
17
16
|
"url": "https://github.com/stacksjs/stacks/issues"
|
|
@@ -31,34 +30,38 @@
|
|
|
31
30
|
],
|
|
32
31
|
"exports": {
|
|
33
32
|
".": {
|
|
34
|
-
"
|
|
35
|
-
"import": "./dist/index.
|
|
33
|
+
"bun": "./src/index.ts",
|
|
34
|
+
"import": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./*": {
|
|
37
|
+
"bun": "./src/*",
|
|
38
|
+
"import": "./dist/*"
|
|
36
39
|
}
|
|
37
40
|
},
|
|
38
|
-
"module": "dist/index.
|
|
41
|
+
"module": "dist/index.js",
|
|
39
42
|
"types": "dist/index.d.ts",
|
|
40
43
|
"contributors": [
|
|
41
|
-
"Chris Breuer <chris@
|
|
44
|
+
"Chris Breuer <chris@stacksjs.org>"
|
|
42
45
|
],
|
|
43
46
|
"files": [
|
|
44
|
-
"
|
|
45
|
-
"
|
|
47
|
+
"README.md",
|
|
48
|
+
"dist"
|
|
46
49
|
],
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "bun --bun build.ts",
|
|
52
|
+
"typecheck": "bun --bun tsc --noEmit",
|
|
53
|
+
"prepublishOnly": "bun --bun run build"
|
|
54
|
+
},
|
|
47
55
|
"peerDependencies": {
|
|
48
|
-
"
|
|
56
|
+
"@stacksjs/cli": "workspace:*",
|
|
57
|
+
"@stacksjs/ui": "workspace:*"
|
|
49
58
|
},
|
|
50
59
|
"dependencies": {
|
|
51
|
-
"@
|
|
52
|
-
"
|
|
53
|
-
"@stacksjs/ui": "0.57.3"
|
|
60
|
+
"@opensearch-project/opensearch": "^2.5.0",
|
|
61
|
+
"meilisearch": "^0.36.0"
|
|
54
62
|
},
|
|
55
63
|
"devDependencies": {
|
|
56
|
-
"@stacksjs/
|
|
57
|
-
"@stacksjs/
|
|
58
|
-
},
|
|
59
|
-
"scripts": {
|
|
60
|
-
"build": "unbuild",
|
|
61
|
-
"dev": "unbuild --stub",
|
|
62
|
-
"typecheck": "tsc --noEmit"
|
|
64
|
+
"@stacksjs/config": "workspace:*",
|
|
65
|
+
"@stacksjs/development": "workspace:*"
|
|
63
66
|
}
|
|
64
|
-
}
|
|
67
|
+
}
|
package/LICENSE.md
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022 Open Web Foundation
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/dist/drivers/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as meilisearch from './meilisearch';
|
package/dist/drivers/index.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as meilisearch from "./meilisearch.mjs";
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { MeiliSearch } from 'meilisearch';
|
|
2
|
-
import type { SearchResponse } from 'meilisearch';
|
|
3
|
-
interface SearchEngineOptions {
|
|
4
|
-
host: string;
|
|
5
|
-
apiKey: string;
|
|
6
|
-
}
|
|
7
|
-
declare function client(options?: SearchEngineOptions): MeiliSearch;
|
|
8
|
-
declare function search(index: string, params: any): Promise<SearchResponse<Record<string, any>>>;
|
|
9
|
-
export { client, search, };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { log } from "@stacksjs/cli";
|
|
2
|
-
import { searchEngine } from "@stacksjs/config";
|
|
3
|
-
import { MeiliSearch } from "meilisearch";
|
|
4
|
-
function client(options) {
|
|
5
|
-
let host = searchEngine.meilisearch?.host;
|
|
6
|
-
let apiKey = searchEngine.meilisearch?.apiKey;
|
|
7
|
-
if (options?.host)
|
|
8
|
-
host = options.host;
|
|
9
|
-
if (options?.apiKey)
|
|
10
|
-
apiKey = options.apiKey;
|
|
11
|
-
if (!host) {
|
|
12
|
-
log.error("Please specify a search engine host.");
|
|
13
|
-
process.exit();
|
|
14
|
-
}
|
|
15
|
-
return new MeiliSearch({ host, apiKey });
|
|
16
|
-
}
|
|
17
|
-
async function search(index, params) {
|
|
18
|
-
return await client().index(index).search(params.query, { limit: params.perPage, offset: params.page * params.perPage });
|
|
19
|
-
}
|
|
20
|
-
export {
|
|
21
|
-
client,
|
|
22
|
-
search
|
|
23
|
-
};
|
package/dist/helpers.d.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is used to define the types/interfaces used in the project.
|
|
3
|
-
*/
|
|
4
|
-
import type { Hits, SearchResponse } from 'meilisearch';
|
|
5
|
-
export interface SearchEngineStore {
|
|
6
|
-
/**
|
|
7
|
-
* The search engine index.
|
|
8
|
-
*/
|
|
9
|
-
index: string;
|
|
10
|
-
/**
|
|
11
|
-
* The search engine host.
|
|
12
|
-
* @default 'http://127.0.0.1:7700'
|
|
13
|
-
*/
|
|
14
|
-
source?: string;
|
|
15
|
-
/**
|
|
16
|
-
* The search engine password/API key.
|
|
17
|
-
*/
|
|
18
|
-
password?: string;
|
|
19
|
-
/**
|
|
20
|
-
* The search query.
|
|
21
|
-
* @default 20
|
|
22
|
-
* @type {string}
|
|
23
|
-
* @default: ''
|
|
24
|
-
*/
|
|
25
|
-
query?: string;
|
|
26
|
-
/**
|
|
27
|
-
* The number of results to return.
|
|
28
|
-
* @default 20
|
|
29
|
-
* @type {number}
|
|
30
|
-
*/
|
|
31
|
-
perPage?: number;
|
|
32
|
-
/**
|
|
33
|
-
* The current page number
|
|
34
|
-
* @default 1
|
|
35
|
-
* @type {number}
|
|
36
|
-
*/
|
|
37
|
-
currentPage?: number;
|
|
38
|
-
/**
|
|
39
|
-
* The results object returned from the search engine.
|
|
40
|
-
*/
|
|
41
|
-
results?: SearchResponse<Record<string, any>>;
|
|
42
|
-
/**
|
|
43
|
-
* The hits object returned from the search engine.
|
|
44
|
-
*/
|
|
45
|
-
hits?: Hits<Record<string, any>>;
|
|
46
|
-
/**
|
|
47
|
-
* The search Filter Name
|
|
48
|
-
*/
|
|
49
|
-
filterName?: string;
|
|
50
|
-
/**
|
|
51
|
-
* The search filters
|
|
52
|
-
*/
|
|
53
|
-
filters?: object;
|
|
54
|
-
/**
|
|
55
|
-
* The next page value
|
|
56
|
-
*/
|
|
57
|
-
goToNextPage?: number;
|
|
58
|
-
/**
|
|
59
|
-
* Set to go to a specific page
|
|
60
|
-
*/
|
|
61
|
-
goToPage?: number;
|
|
62
|
-
/**
|
|
63
|
-
* Set to go to the previous page
|
|
64
|
-
*/
|
|
65
|
-
goToPrevPage?: number;
|
|
66
|
-
/**
|
|
67
|
-
* The last page number value
|
|
68
|
-
*/
|
|
69
|
-
lastPageNumber?: number;
|
|
70
|
-
/**
|
|
71
|
-
* The searched term to use for the search
|
|
72
|
-
*/
|
|
73
|
-
search?: string;
|
|
74
|
-
/**
|
|
75
|
-
* The search params filters to use for the search
|
|
76
|
-
*/
|
|
77
|
-
searchFilters?: object;
|
|
78
|
-
/**
|
|
79
|
-
* The search params to use for the search
|
|
80
|
-
*/
|
|
81
|
-
searchParams?: object;
|
|
82
|
-
/**
|
|
83
|
-
* Total hits value to use for the search
|
|
84
|
-
*/
|
|
85
|
-
setTotalHits?: number;
|
|
86
|
-
/**
|
|
87
|
-
* The sort value to use for the search
|
|
88
|
-
*/
|
|
89
|
-
sort?: string;
|
|
90
|
-
/**
|
|
91
|
-
* The sorts value to use for the search
|
|
92
|
-
*/
|
|
93
|
-
sorts?: object;
|
|
94
|
-
}
|
|
95
|
-
export declare function determineState(): SearchEngineStore;
|
package/dist/helpers.mjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export function determineState() {
|
|
2
|
-
const ls = localStorage.getItem("search-engine");
|
|
3
|
-
if (isString(ls))
|
|
4
|
-
return JSON.parse(ls);
|
|
5
|
-
return {
|
|
6
|
-
// default state
|
|
7
|
-
source: "http://127.0.0.1:7700",
|
|
8
|
-
index: "",
|
|
9
|
-
perPage: 20,
|
|
10
|
-
currentPage: 1,
|
|
11
|
-
query: ""
|
|
12
|
-
};
|
|
13
|
-
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { client as meilisearch } from './drivers/meilisearch';
|
|
2
|
-
export declare const totalPages: any;
|
|
3
|
-
export declare const currentPage: any;
|
|
4
|
-
export declare const filterName: any;
|
|
5
|
-
export declare const filters: any;
|
|
6
|
-
export declare const goToNextPage: any;
|
|
7
|
-
export declare const goToPage: any;
|
|
8
|
-
export declare const goToPrevPage: any;
|
|
9
|
-
export declare const hits: any;
|
|
10
|
-
export declare const index: any;
|
|
11
|
-
export declare const lastPageNumber: any;
|
|
12
|
-
export declare const perPage: any;
|
|
13
|
-
export declare const query: any;
|
|
14
|
-
export declare const results: any;
|
|
15
|
-
export declare const searchFilters: any;
|
|
16
|
-
export declare const searchParams: any;
|
|
17
|
-
export declare const setTotalHits: any;
|
|
18
|
-
export declare const sort: any;
|
|
19
|
-
export declare const sorts: any;
|
|
20
|
-
export declare function client(): typeof meilisearch | undefined;
|
|
21
|
-
export declare function useSearchEngine(): typeof meilisearch | undefined;
|
|
22
|
-
export declare function calculatePagination(): void;
|
package/dist/index.mjs
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { searchEngine } from "@stacksjs/config";
|
|
2
|
-
import { client as meilisearch } from "./drivers/meilisearch.mjs";
|
|
3
|
-
import { determineState } from "./helpers.mjs";
|
|
4
|
-
const table = useStorage("table", determineState()).value;
|
|
5
|
-
const totalHits = table.results?.estimatedTotalHits ?? 1;
|
|
6
|
-
const pages = ref([]);
|
|
7
|
-
export const totalPages = ref(0);
|
|
8
|
-
export const currentPage = computed(() => table.currentPage);
|
|
9
|
-
export const filterName = computed(() => table.filterName);
|
|
10
|
-
export const filters = computed(() => table.filters);
|
|
11
|
-
export const goToNextPage = computed(() => table.goToNextPage);
|
|
12
|
-
export const goToPage = computed(() => table.goToPage);
|
|
13
|
-
export const goToPrevPage = computed(() => table.goToPrevPage);
|
|
14
|
-
export const hits = computed(() => table.hits);
|
|
15
|
-
export const index = computed(() => table.index);
|
|
16
|
-
export const lastPageNumber = computed(() => table.lastPageNumber);
|
|
17
|
-
export const perPage = computed(() => table.perPage);
|
|
18
|
-
export const query = computed(() => table.query);
|
|
19
|
-
export const results = computed(() => table.results);
|
|
20
|
-
export const searchFilters = computed(() => table.searchFilters);
|
|
21
|
-
export const searchParams = computed(() => table.searchParams);
|
|
22
|
-
export const setTotalHits = computed(() => table.setTotalHits);
|
|
23
|
-
export const sort = computed(() => table.sort);
|
|
24
|
-
export const sorts = computed(() => table.sorts);
|
|
25
|
-
export function client() {
|
|
26
|
-
if (searchEngine.driver === "meilisearch")
|
|
27
|
-
return meilisearch;
|
|
28
|
-
}
|
|
29
|
-
export function useSearchEngine() {
|
|
30
|
-
return client();
|
|
31
|
-
}
|
|
32
|
-
export function calculatePagination() {
|
|
33
|
-
if (table.perPage)
|
|
34
|
-
totalPages.value = Math.ceil(totalHits / table.perPage);
|
|
35
|
-
const hitPages = [...Array(totalPages.value).keys()].map((i) => i + 1);
|
|
36
|
-
const offset = 2;
|
|
37
|
-
const currentPage2 = table.currentPage ?? 1;
|
|
38
|
-
const lastPage = hitPages[hitPages.length - 1];
|
|
39
|
-
let from = currentPage2 - offset;
|
|
40
|
-
if (from < 1)
|
|
41
|
-
from = 1;
|
|
42
|
-
let to = from + offset * 2;
|
|
43
|
-
if (to >= lastPage)
|
|
44
|
-
to = lastPage;
|
|
45
|
-
const allPages = [];
|
|
46
|
-
for (let page = from; page <= to; page++)
|
|
47
|
-
allPages.push(page);
|
|
48
|
-
pages.value = allPages;
|
|
49
|
-
}
|