Skip to content

Commit

Permalink
add rudimentary support for searching for nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas-C committed Mar 7, 2025
1 parent 528be2e commit 974a236
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/containers/SearchPageV2/ResourceTypeFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
} from "@ndla/primitives";
import { styled } from "@ndla/styled-system/jsx";
import { FilterContainer } from "./FilterContainer";
import { RESOURCE_NODE_TYPE, TOPIC_NODE_TYPE } from "./searchUtils";
import { RESOURCE_NODE_TYPE, SUBJECT_NODE_TYPE, TOPIC_NODE_TYPE } from "./searchUtils";
import { useStableSearchPageParams } from "./useStableSearchParams";
import {
GQLResourceTypeFilter_BucketResultFragment,
Expand Down Expand Up @@ -97,7 +97,7 @@ const CheckboxWrapper = styled("div", {
},
});

const NODE_TYPES = [TOPIC_NODE_TYPE, RESOURCE_NODE_TYPE];
const NODE_TYPES = [SUBJECT_NODE_TYPE, TOPIC_NODE_TYPE, RESOURCE_NODE_TYPE];

export const ResourceTypeFilter = ({ bucketResult, resourceTypes: resourceTypesProp, resourceTypesLoading }: Props) => {
const [searchParams, setSearchParams] = useStableSearchPageParams();
Expand Down
8 changes: 7 additions & 1 deletion src/containers/SearchPageV2/SearchContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ const searchQueryFragment = gql`
$aggregatePaths: [String!]
$filterInactive: Boolean
$license: String
$resultTypes: String
$nodeTypes: String
) {
search(
query: $query
Expand All @@ -153,6 +155,8 @@ const searchQueryFragment = gql`
aggregatePaths: $aggregatePaths
filterInactive: $filterInactive
license: $license
resultTypes: $resultTypes
nodeTypes: $nodeTypes
) {
page
pageSize
Expand Down Expand Up @@ -218,7 +222,9 @@ const getTypeVariables = (
// TODO: Figure out if we want this. It depends on what search approach we go for
if (nodeType !== RESOURCE_NODE_TYPE) {
return {
contextTypes: nodeType === "topic" ? "topic-article" : nodeType,
contextTypes: nodeType === "topic" ? "topic-article" : nodeType === "subject" ? "subject" : nodeType,
resultTypes: nodeType === "subject" ? "node" : undefined,
nodeTypes: nodeType === "subject" ? "SUBJECT" : undefined,
};
}

Expand Down
120 changes: 107 additions & 13 deletions src/graphqlTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export type GQLArticleSearchResult = GQLSearchResult & {
context?: Maybe<GQLSearchContext>;
contexts: Array<GQLSearchContext>;
htmlTitle: Scalars["String"]["output"];
id: Scalars["Int"]["output"];
id: Scalars["String"]["output"];
metaDescription: Scalars["String"]["output"];
metaImage?: Maybe<GQLMetaImage>;
supportedLanguages: Array<Scalars["String"]["output"]>;
Expand Down Expand Up @@ -782,7 +782,7 @@ export type GQLLearningpathSearchResult = GQLSearchResult & {
context?: Maybe<GQLSearchContext>;
contexts: Array<GQLSearchContext>;
htmlTitle: Scalars["String"]["output"];
id: Scalars["Int"]["output"];
id: Scalars["String"]["output"];
metaDescription: Scalars["String"]["output"];
metaImage?: Maybe<GQLMetaImage>;
supportedLanguages: Array<Scalars["String"]["output"]>;
Expand Down Expand Up @@ -1223,6 +1223,20 @@ export type GQLNodeChildrenArgs = {
recursive?: InputMaybe<Scalars["Boolean"]["input"]>;
};

export type GQLNodeSearchResult = GQLSearchResult & {
__typename?: "NodeSearchResult";
context?: Maybe<GQLSearchContext>;
contexts: Array<GQLSearchContext>;
htmlTitle: Scalars["String"]["output"];
id: Scalars["String"]["output"];
metaDescription: Scalars["String"]["output"];
metaImage?: Maybe<GQLMetaImage>;
supportedLanguages: Array<Scalars["String"]["output"]>;
title: Scalars["String"]["output"];
traits: Array<Scalars["String"]["output"]>;
url: Scalars["String"]["output"];
};

export type GQLOwner = {
__typename?: "Owner";
name: Scalars["String"]["output"];
Expand Down Expand Up @@ -1430,10 +1444,12 @@ export type GQLQueryGroupSearchArgs = {
language?: InputMaybe<Scalars["String"]["input"]>;
levels?: InputMaybe<Scalars["String"]["input"]>;
license?: InputMaybe<Scalars["String"]["input"]>;
nodeTypes?: InputMaybe<Scalars["String"]["input"]>;
page?: InputMaybe<Scalars["Int"]["input"]>;
pageSize?: InputMaybe<Scalars["Int"]["input"]>;
query?: InputMaybe<Scalars["String"]["input"]>;
resourceTypes?: InputMaybe<Scalars["String"]["input"]>;
resultTypes?: InputMaybe<Scalars["String"]["input"]>;
subjects?: InputMaybe<Scalars["String"]["input"]>;
};

Expand Down Expand Up @@ -1536,11 +1552,13 @@ export type GQLQuerySearchArgs = {
languageFilter?: InputMaybe<Scalars["String"]["input"]>;
levels?: InputMaybe<Scalars["String"]["input"]>;
license?: InputMaybe<Scalars["String"]["input"]>;
nodeTypes?: InputMaybe<Scalars["String"]["input"]>;
page?: InputMaybe<Scalars["Int"]["input"]>;
pageSize?: InputMaybe<Scalars["Int"]["input"]>;
query?: InputMaybe<Scalars["String"]["input"]>;
relevance?: InputMaybe<Scalars["String"]["input"]>;
resourceTypes?: InputMaybe<Scalars["String"]["input"]>;
resultTypes?: InputMaybe<Scalars["String"]["input"]>;
sort?: InputMaybe<Scalars["String"]["input"]>;
subjects?: InputMaybe<Scalars["String"]["input"]>;
traits?: InputMaybe<Array<Scalars["String"]["input"]>>;
Expand All @@ -1554,9 +1572,11 @@ export type GQLQuerySearchWithoutPaginationArgs = {
languageFilter?: InputMaybe<Scalars["String"]["input"]>;
levels?: InputMaybe<Scalars["String"]["input"]>;
license?: InputMaybe<Scalars["String"]["input"]>;
nodeTypes?: InputMaybe<Scalars["String"]["input"]>;
query?: InputMaybe<Scalars["String"]["input"]>;
relevance?: InputMaybe<Scalars["String"]["input"]>;
resourceTypes?: InputMaybe<Scalars["String"]["input"]>;
resultTypes?: InputMaybe<Scalars["String"]["input"]>;
sort?: InputMaybe<Scalars["String"]["input"]>;
subjects?: InputMaybe<Scalars["String"]["input"]>;
};
Expand Down Expand Up @@ -1715,7 +1735,7 @@ export type GQLSearchResult = {
context?: Maybe<GQLSearchContext>;
contexts: Array<GQLSearchContext>;
htmlTitle: Scalars["String"]["output"];
id: Scalars["Int"]["output"];
id: Scalars["String"]["output"];
metaDescription: Scalars["String"]["output"];
metaImage?: Maybe<GQLMetaImage>;
supportedLanguages: Array<Scalars["String"]["output"]>;
Expand Down Expand Up @@ -2447,7 +2467,7 @@ export type GQLAllMoviesQuery = {
results: Array<
| {
__typename?: "ArticleSearchResult";
id: number;
id: string;
metaDescription: string;
title: string;
metaImage?: { __typename?: "MetaImage"; url: string };
Expand All @@ -2462,7 +2482,22 @@ export type GQLAllMoviesQuery = {
}
| {
__typename?: "LearningpathSearchResult";
id: number;
id: string;
metaDescription: string;
title: string;
metaImage?: { __typename?: "MetaImage"; url: string };
contexts: Array<{
__typename?: "SearchContext";
contextId: string;
contextType: string;
path: string;
url: string;
rootId: string;
}>;
}
| {
__typename?: "NodeSearchResult";
id: string;
metaDescription: string;
title: string;
metaImage?: { __typename?: "MetaImage"; url: string };
Expand Down Expand Up @@ -2541,7 +2576,7 @@ export type GQLResourceTypeMoviesQuery = {
results: Array<
| {
__typename?: "ArticleSearchResult";
id: number;
id: string;
metaDescription: string;
title: string;
metaImage?: { __typename?: "MetaImage"; url: string };
Expand All @@ -2555,7 +2590,21 @@ export type GQLResourceTypeMoviesQuery = {
}
| {
__typename?: "LearningpathSearchResult";
id: number;
id: string;
metaDescription: string;
title: string;
metaImage?: { __typename?: "MetaImage"; url: string };
contexts: Array<{
__typename?: "SearchContext";
contextId: string;
contextType: string;
url: string;
rootId: string;
}>;
}
| {
__typename?: "NodeSearchResult";
id: string;
metaDescription: string;
title: string;
metaImage?: { __typename?: "MetaImage"; url: string };
Expand Down Expand Up @@ -3698,6 +3747,8 @@ export type GQLNewSearchQueryQueryVariables = Exact<{
aggregatePaths?: InputMaybe<Array<Scalars["String"]["input"]> | Scalars["String"]["input"]>;
filterInactive?: InputMaybe<Scalars["Boolean"]["input"]>;
license?: InputMaybe<Scalars["String"]["input"]>;
resultTypes?: InputMaybe<Scalars["String"]["input"]>;
nodeTypes?: InputMaybe<Scalars["String"]["input"]>;
}>;

export type GQLNewSearchQueryQuery = {
Expand All @@ -3711,6 +3762,7 @@ export type GQLNewSearchQueryQuery = {
results: Array<
| ({ __typename?: "ArticleSearchResult" } & GQLSearchResult_SearchResult_ArticleSearchResult_Fragment)
| ({ __typename?: "LearningpathSearchResult" } & GQLSearchResult_SearchResult_LearningpathSearchResult_Fragment)
| ({ __typename?: "NodeSearchResult" } & GQLSearchResult_SearchResult_NodeSearchResult_Fragment)
>;
aggregations: Array<{
__typename?: "AggregationResult";
Expand Down Expand Up @@ -3739,7 +3791,7 @@ export type GQLSearchResourceTypesQuery = {

type GQLSearchResult_SearchResult_ArticleSearchResult_Fragment = {
__typename?: "ArticleSearchResult";
id: number;
id: string;
url: string;
htmlTitle: string;
title: string;
Expand All @@ -3765,7 +3817,33 @@ type GQLSearchResult_SearchResult_ArticleSearchResult_Fragment = {

type GQLSearchResult_SearchResult_LearningpathSearchResult_Fragment = {
__typename?: "LearningpathSearchResult";
id: number;
id: string;
url: string;
htmlTitle: string;
title: string;
metaDescription: string;
context?: {
__typename?: "SearchContext";
contextId: string;
publicId: string;
url: string;
breadcrumbs: Array<string>;
resourceTypes: Array<{ __typename?: "SearchContextResourceTypes"; id: string; name: string }>;
};
contexts: Array<{
__typename?: "SearchContext";
contextId: string;
publicId: string;
url: string;
breadcrumbs: Array<string>;
relevanceId: string;
resourceTypes: Array<{ __typename?: "SearchContextResourceTypes"; id: string; name: string }>;
}>;
};

type GQLSearchResult_SearchResult_NodeSearchResult_Fragment = {
__typename?: "NodeSearchResult";
id: string;
url: string;
htmlTitle: string;
title: string;
Expand All @@ -3791,7 +3869,8 @@ type GQLSearchResult_SearchResult_LearningpathSearchResult_Fragment = {

export type GQLSearchResult_SearchResultFragment =
| GQLSearchResult_SearchResult_ArticleSearchResult_Fragment
| GQLSearchResult_SearchResult_LearningpathSearchResult_Fragment;
| GQLSearchResult_SearchResult_LearningpathSearchResult_Fragment
| GQLSearchResult_SearchResult_NodeSearchResult_Fragment;

export type GQLSubjectFilterQueryVariables = Exact<{ [key: string]: never }>;

Expand Down Expand Up @@ -4090,7 +4169,7 @@ export type GQLGroupSearchResourceFragment = {

type GQLSearchResource_ArticleSearchResult_Fragment = {
__typename?: "ArticleSearchResult";
id: number;
id: string;
title: string;
htmlTitle: string;
supportedLanguages: Array<string>;
Expand All @@ -4103,7 +4182,20 @@ type GQLSearchResource_ArticleSearchResult_Fragment = {

type GQLSearchResource_LearningpathSearchResult_Fragment = {
__typename?: "LearningpathSearchResult";
id: number;
id: string;
title: string;
htmlTitle: string;
supportedLanguages: Array<string>;
url: string;
metaDescription: string;
traits: Array<string>;
metaImage?: { __typename?: "MetaImage"; url: string; alt: string };
contexts: Array<{ __typename?: "SearchContext" } & GQLSearchContextFragment>;
};

type GQLSearchResource_NodeSearchResult_Fragment = {
__typename?: "NodeSearchResult";
id: string;
title: string;
htmlTitle: string;
supportedLanguages: Array<string>;
Expand All @@ -4116,7 +4208,8 @@ type GQLSearchResource_LearningpathSearchResult_Fragment = {

export type GQLSearchResourceFragment =
| GQLSearchResource_ArticleSearchResult_Fragment
| GQLSearchResource_LearningpathSearchResult_Fragment;
| GQLSearchResource_LearningpathSearchResult_Fragment
| GQLSearchResource_NodeSearchResult_Fragment;

export type GQLSearchQueryVariables = Exact<{
query?: InputMaybe<Scalars["String"]["input"]>;
Expand Down Expand Up @@ -4150,6 +4243,7 @@ export type GQLSearchQuery = {
results: Array<
| ({ __typename?: "ArticleSearchResult" } & GQLSearchResource_ArticleSearchResult_Fragment)
| ({ __typename?: "LearningpathSearchResult" } & GQLSearchResource_LearningpathSearchResult_Fragment)
| ({ __typename?: "NodeSearchResult" } & GQLSearchResource_NodeSearchResult_Fragment)
>;
suggestions: Array<{
__typename?: "SuggestionResult";
Expand Down
1 change: 1 addition & 0 deletions src/messages/messagesEN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const messages = {
title: "Choose page type",
showSubtypes: "Show subtypes for {{parent}}",
resourceLabel: "Resource",
subjectLabel: "Subject",
topicLabel: "Topic",
hits: "{{count}} hits",
},
Expand Down
1 change: 1 addition & 0 deletions src/messages/messagesNB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const messages = {
showSubtypes: "Vis undertyper for {{parent}}",
resourceLabel: "Ressurs",
topicLabel: "Emne",
subjectLabel: "Fag",
hits: "{{count}} treff",
},
noHits: "Ingen artikler samsvarte med søket ditt på: {{query}}",
Expand Down
1 change: 1 addition & 0 deletions src/messages/messagesNN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const messages = {
title: "Vel sidetype",
showSubtypes: "Vis undertypar for {{parent}}",
resourceLabel: "Ressurs",
subjectLabel: "Fag",
topicLabel: "Emne",
hits: "{{count}} treff",
},
Expand Down
1 change: 1 addition & 0 deletions src/messages/messagesSE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const messages = {
title: "Velg sidetype",
showSubtypes: "Vis undertyper for {{parent}}",
resourceLabel: "Ressurs",
subjectLabel: "Fag",
topicLabel: "Emne",
hits: "{{count}} treff",
},
Expand Down
Loading

0 comments on commit 974a236

Please sign in to comment.