Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Viser highlighting i søketreff #278

Merged
merged 3 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/client/src/views/context-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { type AnalyticsEventArgs } from "../analytics/constants";
import { createEvent, CustomEvents } from "../events";
import { Context } from "decorator-shared/params";
import { CustomLinkElement } from "../helpers/custom-link-element";
import { amplitudeEvent } from "../analytics/amplitude";

class ContextLink extends CustomLinkElement {
handleActiveContext = (
Expand Down Expand Up @@ -41,7 +42,7 @@ class ContextLink extends CustomLinkElement {
context: window.__DECORATOR_DATA__.params.context,
...eventArgs,
};
window.analyticsEvent(payload);
amplitudeEvent(payload);
}
};

Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/views/lenke-med-sporing.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AnalyticsEventArgs } from "../analytics/constants";
import { tryParse } from "decorator-shared/json";
import { CustomLinkElement } from "../helpers/custom-link-element";
import { amplitudeEvent } from "../analytics/amplitude";

export class LenkeMedSporingElement extends CustomLinkElement {
constructor() {
Expand All @@ -18,7 +19,7 @@ export class LenkeMedSporingElement extends CustomLinkElement {
context: window.__DECORATOR_DATA__.params.context,
...eventArgs,
};
window.analyticsEvent(payload);
amplitudeEvent(payload);
});
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/views/search-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import html from "decorator-shared/html";
import debounce from "lodash.debounce";
import cls from "../styles/search-form.module.css";
import { env, param } from "../params";
import { amplitudeEvent } from "../analytics/amplitude";

class SearchMenu extends HTMLElement {
form: HTMLFormElement | null = null;
Expand Down Expand Up @@ -51,7 +52,7 @@ class SearchMenu extends HTMLElement {
.map(([key, value]) => `${key}=${value}`)
.join("&")}`;

window.analyticsEvent({
amplitudeEvent({
eventName: "søk",
destination: url,
category: "dekorator-header",
Expand Down
13 changes: 2 additions & 11 deletions packages/server/src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,8 @@ export const search = ({
`${env.SEARCH_API}?ord=${encodeURIComponent(query)}&f=${context}&preferredLanguage=${language}`,
)
.then((res) => res.json() as Promise<SearchResult>)
.then((result) => ({
hits: result.hits?.slice(0, 5).map((hit) => ({
// TODO: kan limit(5) gjøres i søketjenesten
...hit,
highlight: hit.highlight // TODO: replace() i søketjenesten
.replace(/<\/?[^>]+(>|$)/g, "") // Remove html
.replace(/\[.*?(\])/g, "") // Remove shortcodes
.replace(/(\[|<).*?(\(...\))/g, ""), // Remove incomplete html/shortcodes
})),
total: result.total,
}))
// TODO: implement a count-parameter in the search api?
.then((result) => ({ ...result, hits: result.hits.slice(0, 5) }))
.catch((err) => {
console.error(`Error from search api - ${err}`);

Expand Down
6 changes: 4 additions & 2 deletions packages/server/src/views/search-hits.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import html from "decorator-shared/html";
import html, { unsafeHtml } from "decorator-shared/html";
import { SearchResult, Texts } from "decorator-shared/types";
import cls from "decorator-client/src/styles/search-hits.module.css";
import { ForwardChevron } from "decorator-shared/views/icons";
Expand Down Expand Up @@ -42,7 +42,9 @@ export const SearchHits = ({
<h2 class="${cls.title}">
${hit.displayName}
</h2>
<div>${hit.highlight}</div>
<div>
${unsafeHtml(hit.highlight)}
</div>
</div>
</lenke-med-sporing>
</li>
Expand Down
Loading