Skip to content

Commit

Permalink
fix(lxlweb): Continue showing error page for _invalid when not using …
Browse files Browse the repository at this point in the history
…Supersearch (#1195)

* fix(lxlweb): Continue showing error page for _invalid when not using supersearch
  • Loading branch information
jesperengstrom authored Dec 20, 2024
1 parent a3352d9 commit 2cba5f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lxl-web/src/lib/types/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ type MappingObj = { [key in SearchOperators]: SearchMapping[] | string | FramedD

export interface SearchMapping extends MappingObj {
alias: string;
property?: ObjectProperty | DatatypeProperty | PropertyChainAxiom;
property?: ObjectProperty | DatatypeProperty | PropertyChainAxiom | InvalidProperty;
object?: FramedData;
up: { '@id': string };
}
Expand All @@ -148,6 +148,11 @@ export interface DatatypeProperty {
'@id': string;
}

interface InvalidProperty {
'@type': '_Invalid';
label: string;
}

interface PropertyChainAxiom {
propertyChainAxiom: (ObjectProperty | DatatypeProperty)[];
label: string; // e.g. "instanceOf language"
Expand Down
14 changes: 13 additions & 1 deletion lxl-web/src/lib/utils/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { type LocaleCode as LangCode } from '$lib/i18n/locales';
import { bestImage, bestSize, toSecure } from '$lib/utils/auxd';
import getAtPath from '$lib/utils/getAtPath';
import { getUriSlug } from '$lib/utils/http';
import { error } from '@sveltejs/kit';
import { env } from '$env/dynamic/public';

export async function asResult(
view: PartialCollectionView,
Expand Down Expand Up @@ -90,6 +92,16 @@ export function displayMappings(
const operator = _hasOperator(m);

if ('property' in m && operator) {
// Mock old behaviour for 'classic' search GUI, i.e show error page
// when encountering an invalid property in order to provide feedback.
// TODO remove this when Supersearch is fully implemented.
const useSuperSearch = env?.PUBLIC_USE_SUPERSEARCH === 'true';
if (!useSuperSearch && m.property?.['@type'] === '_Invalid') {
error(400, {
message: `Invalid query, please check the documentation. Unrecognized property alias: ${m.property?.label ?? ''}`
});
}

const property = m[operator] as FramedData;
return {
...(isObject(m.property) && { '@id': m.property['@id'] }),
Expand All @@ -102,7 +114,7 @@ export function displayMappings(
'No label', // lensandformat?
property:
m.property?.librisQueryCode ||
m.property?.['@id'].replace('https://id.kb.se/vocab/', '') ||
m.property?.['@id']?.replace('https://id.kb.se/vocab/', '') ||
'', //TODO replace with something better
operator,
...('up' in m && { up: replacePath(m.up as Link, usePath) })
Expand Down

0 comments on commit 2cba5f4

Please sign in to comment.