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

Fix: Profile pictures not shown in search results #665 #669

Merged
merged 1 commit into from
Jan 8, 2025
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
29 changes: 29 additions & 0 deletions src/lib/search/searchTypes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { expect, test } from "vitest";
import {
attributesUsedAsLink,
availableSearchIndexes,
listOfattributesUsedAsLink,
} from "./searchTypes";

/**
* Test that all indexes has a link attribute
* To reduce data sent to client during search
* we slice some attributes from the search result
* This test makes sure that we don't slice attributes
* that are used as links.
* All indexes should have at least one such attribute
*/
test("all indexes has attribute that doesn't get sliced", () => {
for (const index of availableSearchIndexes) {
const indexAttributes = attributesUsedAsLink[index];
expect(
indexAttributes,
`Index "${index}" has no attributes that doesn't get sliced`,
).not.toBeUndefined();
expect(Array.isArray(indexAttributes)).toBe(true);
expect(indexAttributes.length > 0).toBe(true);
}
expect(listOfattributesUsedAsLink.length).toBeGreaterThanOrEqual(
availableSearchIndexes.length,
);
});
34 changes: 19 additions & 15 deletions src/lib/search/searchTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,25 +291,29 @@ export type SearchDataWithType =
data: CommitteeSearchReturnAttributes;
};

/**
* The server slices strings before sending them to the client
* to reduce traffic. Some attributes cannot be sliced however,
* since they are used to link to the entry, or e.g. as a image
*/
export const attributesUsedAsLink: {
members: keyof MemberSearchReturnAttributes;
events: keyof EventSearchReturnAttributes;
articles: keyof ArticleSearchReturnAttributes;
songs: keyof SongSearchReturnAttributes;
positions: keyof PositionSearchReturnAttributes;
committees: keyof CommitteeSearchReturnAttributes;
members: Array<keyof MemberSearchReturnAttributes>;
events: Array<keyof EventSearchReturnAttributes>;
articles: Array<keyof ArticleSearchReturnAttributes>;
songs: Array<keyof SongSearchReturnAttributes>;
positions: Array<keyof PositionSearchReturnAttributes>;
committees: Array<keyof CommitteeSearchReturnAttributes>;
} = {
members: "studentId",
events: "slug",
articles: "slug",
songs: "slug",
positions: "dsekId",
committees: "shortName",
members: ["studentId", "picturePath"],
events: ["slug"],
articles: ["slug"],
songs: ["slug"],
positions: ["dsekId"],
committees: ["shortName", "darkImageUrl", "lightImageUrl", "monoImageUrl"],
};

export const listOfattributesUsedAsLink: string[] = Object.values(
attributesUsedAsLink,
) satisfies string[];
export const listOfattributesUsedAsLink: string[] =
Object.values(attributesUsedAsLink).flat();

type DefaultRankingRules =
| "words"
Expand Down
Loading