Skip to content

Commit

Permalink
extended range of fields to search over, adapt index when switching b…
Browse files Browse the repository at this point in the history
…etween entities
  • Loading branch information
joaquinvanschoren committed Jan 2, 2024
1 parent 5396292 commit 0fcbdc7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
13 changes: 8 additions & 5 deletions app/src/components/navbar/NavbarSearch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { memo, useState, useEffect } from "react";
import { useRouter } from "next/router";

import styled from "@emotion/styled";
import { darken } from "polished";
Expand Down Expand Up @@ -92,6 +93,7 @@ const Input = styled(InputBase)`

const SearchBar = memo(() => {
const { t } = useTranslation();
const router = useRouter();

// List of configs for each index
const indexConfigs = {
Expand Down Expand Up @@ -125,15 +127,16 @@ const SearchBar = memo(() => {

// Set the index based on the current path
useEffect(() => {
const pathSegments = window.location.pathname.split("/");
// The index is always the second segment in the URL
const pathSegments = router.pathname.split("/");
const indexFromUrl = pathSegments[1];
// Check if the index is valid before updating the state

if (["d", "t", "f", "r", "b", "c", "m"].includes(indexFromUrl)) {
const index = indices.find((item) => item.key.charAt(0) === indexFromUrl);
setSelectedIndex(index.key);
if (index) {
setSelectedIndex(index.key);
}
}
}, []);
}, [router.pathname]); // Depend on router.pathname to re-run the effect when the route changes

return (
<SearchProvider config={currentConfig}>
Expand Down
2 changes: 1 addition & 1 deletion app/src/pages/api/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default async function handler(req, res) {
}

//This runs server-side, so the output appears in the terminal
//console.log("OnSearch", indexName, requestState, queryConfig);
console.log("OnSearch", indexName, requestState, queryConfig);
const response = await connectorsCache[indexName].onSearch(
requestState,
queryConfig,
Expand Down
11 changes: 10 additions & 1 deletion app/src/pages/d/searchConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@ const searchConfig = {
searchQuery: {
resultsPerPage: 100,
search_fields: {
description: {},
name: { weight: 3 },
exact_name: { weight: 3 },
description: { weight: 3 },
"tags.tag": { weight: 3 },
uploader: { weight: 2 },
format: { weight: 1 },
licence: { weight: 1 },
status: { weight: 1 },
error_message: { weight: 1 },
default_class_attribute: { weight: 1 },
},
result_fields: {
contributor: { raw: {} },
Expand Down
7 changes: 6 additions & 1 deletion app/src/pages/t/searchConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ const searchConfig = {
searchQuery: {
resultsPerPage: 100,
search_fields: {
description: {},
"source_data.name": { weight: 3 },
"tags.tag": { weight: 3 },
"tasktype.name": { weight: 2 },
"estimation_procedure.name": { weight: 2 },
evaluation_measures: { weight: 2 },
target_feature: { weight: 1 },
},
result_fields: {
creator: { raw: {} },
Expand Down

0 comments on commit 0fcbdc7

Please sign in to comment.