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: Search performance and empty results #964

Merged
merged 2 commits into from
Feb 15, 2023
Merged
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
41 changes: 26 additions & 15 deletions app/rdf/query-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import clownface from "clownface";
import { descending } from "d3";
import { Cube } from "rdf-cube-view-query";
import rdf from "rdf-ext";
import { Quad, Stream } from "rdf-js";
import StreamClient from "sparql-http-client";
import ParsingClient from "sparql-http-client/ParsingClient";

Expand Down Expand Up @@ -87,6 +88,15 @@ const parseResultRow = (row: ResultRow) =>
const identity = <T>(str: TemplateResult<T>) => str;
const optional = <T>(str: TemplateResult<T>) => sparql`OPTIONAL { ${str} }`;

const extractCubesFromStream = async (cubeStream: Stream<Quad>) => {
const cubeDataset = await fromStream(rdf.dataset(), cubeStream);
const cf = clownface({ dataset: cubeDataset });
return cf.has(
cf.namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
ns.cube.Cube
);
};

export const searchCubes = async ({
query: rawQuery,
locale,
Expand Down Expand Up @@ -158,6 +168,10 @@ export const searchCubes = async ({
${makeInFilter("theme", themeValues)}
${makeInFilter("creator", creatorValues)}

FILTER(LANG(?name) = LANG(?description))
FILTER(LANG(?name) = LANG(?creatorLabel))
FILTER(LANG(?name) = LANG(?themeName))
Comment on lines +171 to +173
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I edited the description, please tell me if it's clearer.


${
query
? `FILTER(
Expand Down Expand Up @@ -220,23 +234,20 @@ export const searchCubes = async ({
throw new Error("Must pass locale");
}

const { data: cubeStream, meta: cubesMeta } = await executeAndMeasure(
sparqlClientStream,
cubesQuery
);
queries.push({
...cubesMeta,
label: "cubes",
});
const cubeDataset = await fromStream(rdf.dataset(), cubeStream);
const cf = clownface({ dataset: cubeDataset });
const { data: cubeStream, meta: cubesMeta } =
sortedCubeIris.length > 0
? await executeAndMeasure(sparqlClientStream, cubesQuery)
: { data: undefined, meta: undefined };

if (cubesMeta) {
queries.push({
...cubesMeta,
label: "cubes",
});
}
const cubeNodes = cubeStream ? await extractCubesFromStream(cubeStream) : [];
const seen = new Set();
const cubes = cf
.has(
cf.namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
ns.cube.Cube
)
const cubes = cubeNodes
.map((cubeNode) => {
const cube = cubeNode as unknown as Cube;
const iri = parseIri(cube);
Expand Down