Skip to content

Commit

Permalink
Fold metadata into searcher
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasjm committed Mar 5, 2024
1 parent 3272edc commit e3acd8d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
10 changes: 10 additions & 0 deletions codedown/uiMetadata.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,29 @@ rec {
}) // (lib.optionalAttrs (contents ? "meta") (
lib.filterAttrs (n: v:
n == "description"
|| n == "displayName"
|| n == "icon"

|| n == "homepage"
|| n == "downloadPage"
|| n == "changelog"

|| (n == "available" && !v)
|| (n == "broken" && v)
|| (n == "unfree" && v)
|| (n == "unsupported" && v)
|| (n == "insecure" && v)
|| (n == "lessCommon" && v)

|| (n == "maintainers")
)
contents.meta
)) // (lib.optionalAttrs (lib.hasAttrByPath ["meta" "license" "spdxId"] contents) {
spdxId = contents.meta.license.spdxId;
}) // (lib.optionalAttrs (contents ? "settingsSchema") {
inherit (contents) settingsSchema;
}) // (lib.optionalAttrs (contents ? "modes") {
inherit (contents) modes;
});

mkChannelUiMetadata = name: channel: channel // {
Expand Down
19 changes: 6 additions & 13 deletions tools/sqlite-indexer/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
let
common = callPackage ../../languages/common.nix {};

uiMetadata = callPackage ../../codedown/uiMetadata.nix {};

numVersionComponents = 5;
componentPadLength = 3;

Expand All @@ -34,27 +36,21 @@ let
attr = attrPrefix + k;
name = common.safeEval (lib.attrByPath ["meta" "name"] "" v);
version = common.safeEval (common.lexicographyVersionNumber' numVersionComponents componentPadLength (lib.attrByPath ["meta" "version"] "" v));
description = common.safeEval (lib.attrByPath ["meta" "description"] "" v);
display_name = common.safeEval (lib.attrByPath ["meta" "displayName"] "" v);
icon = common.safeEval (lib.attrByPath ["meta" "icon"] "" v);
less_common = common.safeEval (lib.attrByPath ["meta" "lessCommon"] false v);
meta = uiMetadata.chooseInterestingMeta v;
}) filteredPackages));

in

rec {
index = runCommand "search-index.db" { buildInputs = [nodejs sqlite]; inherit json; } ''
echo | sqlite3 $out <<- EOF
CREATE VIRTUAL TABLE main using fts5(attr, name, version, description, display_name, icon UNINDEXED, less_common UNINDEXED);
CREATE VIRTUAL TABLE main using fts5(attr, name, version, meta UNINDEXED);
INSERT INTO main SELECT
json_extract(value, '$.attr'),
json_extract(value, '$.name'),
json_extract(value, '$.version'),
json_extract(value, '$.description'),
json_extract(value, '$.display_name'),
json_extract(value, '$.icon'),
json_extract(value, '$.less_common')
json_extract(value, '$.meta')
FROM json_each(readfile('${json}'));
INSERT INTO main(main) VALUES('optimize');
Expand Down Expand Up @@ -107,10 +103,7 @@ rec {
attr = '$query' as attr_matches,
name,
name = '$query' as name_matches,
description,
display_name,
icon,
less_common,
meta,
rank \
FROM main $filterClause \
ORDER BY \
Expand Down

0 comments on commit e3acd8d

Please sign in to comment.