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

feat(#1): catalogue and recommender integration #37

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

xamcost
Copy link
Collaborator

@xamcost xamcost commented Feb 6, 2025

Description

Hi there! This PR integrates a catalogue instance, as well as a recommender instance, to the marketplace. More precisely, it implements:

  • catalogue browsing: when doing a search, the frontend actually makes a sparql query to retrieve offerings based on text matching with their title OR their description in the catalogue. The list of providers and the list of keywords corresponding to the offerings in the text matching query are also retrieved, for further filtering of the offering results. On the other hand, catalogue navigation is reworked to happen server-side, leveraging URL params.
  • recommendations upon browsing the catalogue, based on the query of the user, displayed alongside search results.
  • when the user selects an offering from the results, the offering details are fetched from the catalogue, as well as some similar offerings from the recommender.

How to test

You will need to port-forward to the Sedimark cluster to access the catalogue and recommender:

kubectl port-forward -n catalogue svc/jena-fuseki 3030:3030  # for the catalogue
kubectl port-forward -n recommender svc/recommender 8000:8000  # for the recommender

Be sure to add the necessary variables to your env. You can check that in the updated example env, but for convenience:

export CATALOGUE_URL="http://localhost:3030"
export RECOMMENDER_URL="http://localhost:8000"

Then as usual:

npm run dev

To-do

  • add participant fetching when selecting an offering
  • rework "back to search" button in selected offering page, to actually get back to the same search query (may become a separated issue)
  • implement streaming to improving catalogue search page loading experience (will very likely become a separate issue): covered by issue Implement streaming to load catalogue queries #39

Closes #1

@xamcost xamcost added Func: Offering Discovery Issues related to catalogue browsing Type: enhancement New feature or request labels Feb 6, 2025
@xamcost xamcost marked this pull request as ready for review February 12, 2025 15:45
Copy link
Collaborator Author

@xamcost xamcost left a comment

Choose a reason for hiding this comment

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

@AlvaroFernandezBejarano This PR is now ready for review! Sorry for the time it took, I got dragged away by other tasks. It implements all of what is mentioned in the original posts, yet to keep the development of catalogue browsing features manageable, I created a few issues for follow up work:

When you'll have time, please have a look and let me know!

Comment on lines +36 to +37
echo "CATALOGUE_URL=${{ secrets.CATALOGUE_URL }}" > .env.production
echo "RECOMMENDER_URL=${{ secrets.RECOMMENDER_URL }}" >> .env.production
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Having these two env variables set is required for the production build to work, otherwise the prefetching of nextjs fails.

@@ -10,7 +12,7 @@ FROM node:20-alpine as builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build
RUN npm run ${BUILD_CMD}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remark: this is really an optional addition, to enable us to build locally or to do a development build with prefetching disabled. I am happy to remove it if you find that irrelevant.

hostname: 'picsum.photos',
port: '',
pathname: '/200'
hostname: '**'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not ideal in terms of security, but we have no choice if we want to be able to render any images stored in the offerings and participants.. if you have any ideas to make this more secure, let me know!

Comment on lines +9 to +10
"compile": "next build --experimental-build-mode compile",
"generate": "next build --experimental-build-mode generate",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This two commands are here to enable us to build the app without prefetching, therefore not requiring valid URLs for the catalogue or recommender. I am happy to remove that if you find this irrelevant.

Comment on lines +6 to +12
const goBack = () => {
if (document.referrer.includes('/catalogue?')) {
window.history.back()
} else {
window.location.href = '/catalogue'
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It may sound unusual to use window.history directly, but I found that more elegant than creating a hook to modify Nextjs' router, which doesn't store the navigation history.

</div>
<div className='pt-2'>
<PriceCard price={asset.price} />
<PriceCard price={offering?.price ?? 0} />
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

NB: price is not part of the Sedimark ontology for the time being.

@@ -8,11 +8,11 @@ function Recommender ({ recommendations }) {
<div className='flex gap-4 overflow-x-auto p-4 w-full'>
{recommendations.map((recommendation, index) => {
return (
<Link key={`${recommendation.title}-${recommendation.created_at}-${index + 1}`} href='#'>
<Link key={`${recommendation.title.value}-${recommendation.created.value}-${index + 1}`} href={`/catalogue/${btoa(recommendation.offering.value)}`}>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

NB: offering IDs are URLs... so to put them in the URL path, they are encoded in base64. I am open to other approaches!

const query = searchParams?.query || ''
const currentPage = Number(searchParams?.page) || 1

return (
<div className='bg-sedimark-dark-deep-blue'>
<SearchBar />
<Suspense
key={type + query + currentPage} // Ensures the Catalogue component is re-rendered when the search parameters change
key={query + currentPage} // Ensures the Catalogue component is re-rendered when the search parameters change
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The type has been removed because we won't distinguish two types of offerings anymore in the project (just datasets, no services).

Comment on lines +7 to +9
<div>
<Image src='/img/ukri-icon.png' height={48} width={149} alt='UKRI' />
</div>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry this addition is not relevant in the PR, but that's something we need to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Func: Offering Discovery Issues related to catalogue browsing Type: enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate catalogue into the marketplace frontend for offering discoverability
1 participant