Skip to content

Commit 3abc31d

Browse files
Implement basic full-text-search (#1359)
1 parent e8fc5f0 commit 3abc31d

File tree

14 files changed

+357
-47
lines changed

14 files changed

+357
-47
lines changed

package-lock.json

Lines changed: 121 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/catalog-api/src/lib/schema.graphql

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,8 @@ type Query {
88
"""
99
Queries custom elements in the entire catalog, from the latest version of each
1010
package.
11-
12-
Eventually this will have more query parameters, and use some sort of ranking
13-
algorithm, otherwise the order will just be defined by the database
14-
implementation.
15-
16-
NOT IMPLEMENTED
17-
DO_NOT_LAUNCH
18-
"""
19-
elements(distTag: String = "latest", limit: Int): [CustomElement!]!
20-
21-
"""
22-
Retrieves the custom element data for a single element.
23-
24-
NOT IMPLEMENTED
25-
DO_NOT_LAUNCH
2611
"""
27-
element(
28-
packageName: String!
29-
elementName: String!
30-
tag: String = "latest"
31-
): CustomElement
12+
elements(query: String, limit: Int): [CustomElement!]!
3213
}
3314

3415
type Mutation {

packages/catalog-server/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,15 @@
8484
"@koa/router": "^12.0.0",
8585
"@types/koa__router": "^12.0.0",
8686
"@types/koa-bodyparser": "^4.3.8",
87+
"@types/natural": "^5.1.1",
8788
"@webcomponents/catalog-api": "0.0.0",
8889
"@webcomponents/custom-elements-manifest-tools": "0.0.0",
8990
"custom-elements-manifest": "^2.0.0",
9091
"firebase": "^9.6.10",
9192
"firebase-admin": "^11.0.0",
9293
"graphql-helix": "^1.13.0",
9394
"koa-bodyparser": "^4.3.0",
95+
"natural": "^5.2.3",
9496
"node-fetch": "^3.2.3",
9597
"npm-registry-fetch": "^13.1.0",
9698
"semver": "^7.3.7"

packages/catalog-server/src/lib/catalog.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,7 @@ export class Catalog {
272272

273273
console.log('Writing custom elements...');
274274
await this.#repository.writeCustomElements(
275-
packageName,
276-
version,
275+
packageVersionMetadata,
277276
customElements,
278277
versionDistTags,
279278
author
@@ -307,11 +306,21 @@ export class Catalog {
307306
return this.#repository.getPackageVersion(packageName, version);
308307
}
309308

309+
/**
310+
* Gets the custom elements for a package
311+
*/
310312
async getCustomElements(
311313
packageName: string,
312314
version: string,
313315
tagName: string | undefined
314316
): Promise<Array<CustomElement>> {
315317
return this.#repository.getCustomElements(packageName, version, tagName);
316318
}
319+
320+
async queryElements({query, limit}: {query?: string; limit?: number}) {
321+
// TODO (justinfagnani): The catalog should parse out GitHub-style search
322+
// operators (like "author:yogibear") and pass structured + text queries
323+
// to the repository
324+
return this.#repository.queryElements({query, limit});
325+
}
317326
}

0 commit comments

Comments
 (0)