From 16153dcc67a685b782edb7343cc5e647d0a2da54 Mon Sep 17 00:00:00 2001 From: pjohans Date: Tue, 31 Oct 2023 11:16:37 +0100 Subject: [PATCH 1/3] removed the q where not needed --- src/components/search/result/Result.js | 3 --- src/pages/avanceret.js | 15 +++++++-------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/components/search/result/Result.js b/src/components/search/result/Result.js index 2503d6306..194e82acd 100644 --- a/src/components/search/result/Result.js +++ b/src/components/search/result/Result.js @@ -24,7 +24,6 @@ import styles from "./Result.module.css"; * See propTypes for specific props and types */ export function Result({ - q, page, isLoading, hitcount = 0, @@ -66,7 +65,6 @@ export function Result({ .map((p, index) => ( @@ -127,7 +125,6 @@ export default function Wrap({ page, onWorkClick, onPageChange }) { return ( 0} isLoading={relatedSubjects.isLoading} diff --git a/src/pages/avanceret.js b/src/pages/avanceret.js index 3e4546c23..1b3c62eba 100644 --- a/src/pages/avanceret.js +++ b/src/pages/avanceret.js @@ -1,24 +1,21 @@ import Header from "@/components/header/Header"; import { useRouter } from "next/router"; import { fetchAll } from "@/lib/api/apiServerOnly"; - import AdvancedSearch from "@/components/search/advancedSearch/AdvancedSearch"; -import Result from "@/components/search/result/Result"; -import useQ from "@/components/hooks/useQ"; import useDataCollect from "@/lib/useDataCollect"; -import useFilters from "@/components/hooks/useFilters"; import { useRef } from "react"; +import AdvancedSearchResult from "@/components/search/advancedSearch/advancedSearchResult/AdvancedSearchResult"; +import isEmpty from "lodash/isEmpty"; /** * Renders AdvancedSearch page */ export default function AdvancedSearchPage() { const router = useRouter(); - const q = useQ().getQuery(); - const filters = useFilters().getQuery(); const dataCollect = useDataCollect(); const scrollRef = useRef(); const { page = 1 } = router.query; + const cql = router?.query?.cql || ""; /** * Updates URL query params @@ -47,14 +44,15 @@ export default function AdvancedSearchPage() {
- {q && ( - { scroll = typeof scroll !== "boolean" || scroll !== false; await updateQueryParams({ page }); scroll && scrollToRef(scrollRef); }} + // .. @TODO .. what to do with the datacollect ?? onWorkClick={(index, work) => { dataCollect.collectSearchWorkClick({ search_request: { q, filters }, @@ -62,6 +60,7 @@ export default function AdvancedSearchPage() { search_query_work: work.workId, }); }} + cql={cql} /> )} From 7955b209428db4cded381a2bffaccb24cc92ef7d Mon Sep 17 00:00:00 2001 From: pjohans Date: Tue, 31 Oct 2023 11:17:14 +0100 Subject: [PATCH 2/3] added fragment for complex search --- src/lib/api/complexSearch.fragments.js | 104 +++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/lib/api/complexSearch.fragments.js diff --git a/src/lib/api/complexSearch.fragments.js b/src/lib/api/complexSearch.fragments.js new file mode 100644 index 000000000..b76849b09 --- /dev/null +++ b/src/lib/api/complexSearch.fragments.js @@ -0,0 +1,104 @@ +/** + * Hitcount + * + * @param {string} q the query + * @param {Object} filters filters for searching + */ +export function doComplexSearchAll({ cql, offset, limit }) { + return { + // delay: 1000, // for debugging + query: ` + query ComplexSearchAll($cql: String!, $offset: Int!, $limit: PaginationLimit!) { + complexSearch(cql: $cql) { + hitcount + errorMessage + works(offset: $offset, limit: $limit) { + workId + mainLanguages { + isoCode + display + } + workTypes + manifestations { + mostRelevant{ + pid + ownerWork { + workTypes + } + cover { + detail + origin + } + materialTypes { + materialTypeGeneral { + code + display + } + materialTypeSpecific { + code + display + } + } + hostPublication { + title + } + publisher + edition { + summary + edition + } + } + } + creators { + ... on Corporation { + __typename + display + nameSort + roles { + function { + plural + singular + } + functionCode + } + } + ... on Person { + __typename + display + nameSort + roles { + function { + plural + singular + } + functionCode + } + } + } + materialTypes { + materialTypeGeneral { + code + display + } + materialTypeSpecific { + code + display + } + } + fictionNonfiction { + display + } + genreAndForm + titles { + main + full + parallel + sort + } + } + } + }`, + variables: { cql, offset, limit }, + slowThreshold: 3000, + }; +} From ea503244ee8362790d7d051226ed7998810a23a2 Mon Sep 17 00:00:00 2001 From: pjohans Date: Tue, 31 Oct 2023 11:17:59 +0100 Subject: [PATCH 3/3] reuse resultpage from simplesearch --- .../AdvancedSearchResult.js | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/components/search/advancedSearch/advancedSearchResult/AdvancedSearchResult.js diff --git a/src/components/search/advancedSearch/advancedSearchResult/AdvancedSearchResult.js b/src/components/search/advancedSearch/advancedSearchResult/AdvancedSearchResult.js new file mode 100644 index 000000000..4c816300f --- /dev/null +++ b/src/components/search/advancedSearch/advancedSearchResult/AdvancedSearchResult.js @@ -0,0 +1,71 @@ +import { doComplexSearchAll } from "@/lib/api/complexSearch.fragments"; +import { useData } from "@/lib/api/api"; +import { ResultPage } from "@/components/search/result/page"; +import Section from "@/components/base/section"; +import Pagination from "@/components/search/pagination/Pagination"; +import PropTypes from "prop-types"; + +export function AdvancedSearchResult({ + page, + onWorkClick, + onPageChange, + results, +}) { + // console.log(page, onPageChange, onWorkClick, cql, "COMPONENT"); + const isLoading = results.isLoading; + const hitcount = results?.data?.complexSearch?.hitcount; + const numPages = Math.ceil(hitcount / 10); + + return ( + <> +
+ +
+ {hitcount > 0 && ( + + )} + + ); +} + +/** + * Load the data needed for the advanced search result. + * + * @returns {React.JSX.Element} + */ +export default function Wrap({ page, onWorkClick, onPageChange, cql }) { + const limit = 10; // limit + let offset = limit * (page - 1); // offset + // use the useData hook to fetch data + const bigResponse = useData( + doComplexSearchAll({ cql, offset: offset, limit: limit }) + ); + + return ( + + ); +} + +Wrap.propTypes = { + page: PropTypes.number, + cql: PropTypes.string, + onViewSelect: PropTypes.func, + onWorkClick: PropTypes.func, +};