Skip to content

Commit

Permalink
Merge pull request #4031 from owid/explorer-lerna-package
Browse files Browse the repository at this point in the history
🔨 extract explorers to lerna package
  • Loading branch information
ikesau authored Nov 8, 2024
2 parents a02927f + f04ea06 commit 1dbd083
Show file tree
Hide file tree
Showing 109 changed files with 2,116 additions and 838 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,10 @@ update.chart-entities: itsJustJavascript
reindex: itsJustJavascript
@echo '==> Reindexing search in Algolia'
node --enable-source-maps itsJustJavascript/baker/algolia/configureAlgolia.js
node --enable-source-maps itsJustJavascript/baker/algolia/indexToAlgolia.js
node --enable-source-maps itsJustJavascript/baker/algolia/indexPagesToAlgolia.js
node --enable-source-maps itsJustJavascript/baker/algolia/indexChartsToAlgolia.js
node --enable-source-maps itsJustJavascript/baker/algolia/indexExplorerViewsToAlgolia.js
node --enable-source-maps itsJustJavascript/baker/algolia/indexExplorerViewsAndChartsToAlgolia.js

delete-algolia-index: itsJustJavascript
@echo '==> Deleting Algolia index'
Expand Down
2 changes: 1 addition & 1 deletion _routes.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": 1,
"include": ["/grapher/*", "/deleted/*", "/donation/*"],
"include": ["/grapher/*", "/deleted/*", "/donation/*", "/explorers/*"],
"exclude": ["/grapher/_grapherRedirects.json"]
}
2 changes: 1 addition & 1 deletion adminSiteClient/AdminApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { AdminAppContext } from "./AdminAppContext.js"
import { Base64 } from "js-base64"
import { ExplorerCreatePage } from "../explorerAdminClient/ExplorerCreatePage.js"
import { ExplorersIndexPage } from "../explorerAdminClient/ExplorersListPage.js"
import { EXPLORERS_ROUTE_FOLDER } from "../explorer/ExplorerConstants.js"
import { EXPLORERS_ROUTE_FOLDER } from "@ourworldindata/explorer"
import { AdminLayout } from "./AdminLayout.js"
import { BulkGrapherConfigEditorPage } from "./BulkGrapherConfigEditor.js"
import { GdocsIndexPage, GdocsMatchProps } from "./GdocsIndexPage.js"
Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/AdminLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome/index.js"
import {
DefaultNewExplorerSlug,
EXPLORERS_ROUTE_FOLDER,
} from "../explorer/ExplorerConstants.js"
} from "@ourworldindata/explorer"
import classNames from "classnames"

@observer
Expand Down
4 changes: 2 additions & 2 deletions adminSiteClient/ExplorerTagsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { DbChartTagJoin } from "@ourworldindata/utils"
import {
GetAllExplorersRoute,
GetAllExplorersTagsRoute,
} from "../explorer/ExplorerConstants.js"
ExplorerProgram,
} from "@ourworldindata/explorer"
import { EditableTags } from "./EditableTags.js"
import { ExplorerProgram } from "../explorer/ExplorerProgram.js"
import cx from "classnames"

type ExplorerWithTags = {
Expand Down
1 change: 0 additions & 1 deletion adminSiteClient/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"rootDir": "."
},
"references": [
{ "path": "../explorer" },
{ "path": "../explorerAdminClient" },
{ "path": "../settings" },
{ "path": "../site" },
Expand Down
4 changes: 1 addition & 3 deletions adminSiteServer/adminRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ import {
EXPLORERS_PREVIEW_ROUTE,
GetAllExplorersRoute,
GetAllExplorersTagsRoute,
} from "../explorer/ExplorerConstants.js"
import {
ExplorerProgram,
EXPLORER_FILE_SUFFIX,
} from "../explorer/ExplorerProgram.js"
} from "@ourworldindata/explorer"
import fs from "fs-extra"
import * as Post from "../db/model/Post.js"
import {
Expand Down
2 changes: 1 addition & 1 deletion adminSiteServer/apiRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ import { denormalizeLatestCountryData } from "../baker/countryProfiles.js"
import {
indexIndividualGdocPost,
removeIndividualGdocPostFromIndex,
} from "../baker/algolia/algoliaUtils.js"
} from "../baker/algolia/utils/pages.js"
import { References } from "../adminSiteClient/ChartEditor.js"
import { DeployQueueServer } from "../baker/DeployQueueServer.js"
import { FunctionalRouter } from "./FunctionalRouter.js"
Expand Down
6 changes: 4 additions & 2 deletions adminSiteServer/mockSiteRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ import {
ImageMetadata,
} from "@ourworldindata/utils"
import { GIT_CMS_DIR } from "../gitCms/GitCmsConstants.js"
import { EXPLORERS_ROUTE_FOLDER } from "../explorer/ExplorerConstants.js"
import {
EXPLORERS_ROUTE_FOLDER,
explorerUrlMigrationsById,
} from "@ourworldindata/explorer"
import { getExplorerRedirectForPath } from "../explorerAdminServer/ExplorerRedirects.js"
import { explorerUrlMigrationsById } from "../explorer/urlMigrations/ExplorerUrlMigrations.js"
import { generateEmbedSnippet } from "../site/viteUtils.js"
import {
renderPreviewDataPageOrGrapherPage,
Expand Down
2 changes: 1 addition & 1 deletion adminSiteServer/testPageRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
} from "@ourworldindata/types"
import { ExplorerAdminServer } from "../explorerAdminServer/ExplorerAdminServer.js"
import { GIT_CMS_DIR } from "../gitCms/GitCmsConstants.js"
import { ExplorerChartCreationMode } from "../explorer/ExplorerConstants.js"
import { ExplorerChartCreationMode } from "@ourworldindata/explorer"
import { getPlainRouteWithROTransaction } from "./plainRouterHelpers.js"
import {
ColorSchemes,
Expand Down
1 change: 0 additions & 1 deletion adminSiteServer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"references": [
{ "path": "../site" },
{ "path": "../db" },
{ "path": "../explorer" },
{ "path": "../explorerAdminServer" },
{ "path": "../gitCms" },
{ "path": "../adminSiteClient" },
Expand Down
10 changes: 6 additions & 4 deletions baker/ExplorerBaker.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import fs from "fs-extra"
import path from "path"
import { ExplorerProgram } from "../explorer/ExplorerProgram.js"
import { explorerUrlMigrationsById } from "../explorer/urlMigrations/ExplorerUrlMigrations.js"
import {
ExplorerProgram,
ExplorerGrammar,
ColumnGrammar,
explorerUrlMigrationsById,
} from "@ourworldindata/explorer"
import { ExplorerAdminServer } from "../explorerAdminServer/ExplorerAdminServer.js"
import { explorerRedirectTable } from "../explorerAdminServer/ExplorerRedirects.js"
import { renderExplorerPage } from "./siteRenderers.js"
import * as db from "../db/db.js"
import { getVariableIdsByCatalogPath } from "../db/model/Variable.js"
import { ExplorerGrammar } from "../explorer/ExplorerGrammar.js"
import {
CoreTable,
ErrorValueTypes,
isNotErrorValueOrEmptyCell,
} from "@ourworldindata/core-table"
import { ColumnGrammar } from "../explorer/ColumnGrammar.js"
import { ColumnTypeNames } from "@ourworldindata/types"

export const transformExplorerProgramToResolveCatalogPaths = async (
Expand Down
2 changes: 1 addition & 1 deletion baker/SiteBaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import {
flushCache as redirectsFlushCache,
} from "./redirects.js"
import { bakeAllChangedGrapherPagesVariablesPngSvgAndDeleteRemovedGraphers } from "./GrapherBaker.js"
import { EXPLORERS_ROUTE_FOLDER } from "../explorer/ExplorerConstants.js"
import { EXPLORERS_ROUTE_FOLDER } from "@ourworldindata/explorer"
import { GIT_CMS_DIR } from "../gitCms/GitCmsConstants.js"
import {
bakeAllExplorerRedirects,
Expand Down
35 changes: 35 additions & 0 deletions baker/algolia/configureAlgolia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,41 @@ export const configureAlgolia = async () => {
],
})

const explorerViewsAndChartsIndex = client.initIndex(
getIndexName(SearchIndexName.ExplorerViewsAndCharts)
)

await explorerViewsAndChartsIndex.setSettings({
...baseSettings,
searchableAttributes: [
"unordered(title)",
"unordered(slug)",
"unordered(variantName)",
"unordered(subtitle)",
"unordered(tags)",
"unordered(availableEntities)",
],
ranking: ["typo", "words", "exact", "attribute", "custom", "proximity"],
customRanking: [
"desc(score)",
// For multiple explorer views with the same title, we want to avoid surfacing duplicates.
// So, rank a result with viewTitleIndexWithinExplorer=0 way more highly than one with 1, 2, etc.
"asc(viewTitleIndexWithinExplorer)",
"asc(titleLength)",
],
attributesToSnippet: ["subtitle:24"],
attributeForDistinct: "id",
optionalWords: ["vs"],

// These lines below essentially demote matches in the `subtitle` and `availableEntities` fields:
// If we find a match (only) there, then it doesn't count towards `exact`, and is therefore ranked lower.
// We also disable prefix matching and typo tolerance on these.
disableExactOnAttributes: ["tags", "subtitle", "availableEntities"],
disableTypoToleranceOnAttributes: ["subtitle", "availableEntities"],
disablePrefixOnAttributes: ["subtitle"],
attributesForFaceting: ["tags", "availableEntities"],
})

const synonyms = [
["owid", "our world in data"],
["kids", "children"],
Expand Down
Loading

0 comments on commit 1dbd083

Please sign in to comment.