Skip to content

Commit

Permalink
III-6018 - Prefill different terms.id fields
Browse files Browse the repository at this point in the history
  • Loading branch information
brampauwelyn committed Mar 11, 2024
1 parent 15c0cf4 commit 76d5ea7
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 24 deletions.
53 changes: 44 additions & 9 deletions dist/udb3-angular.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 44 additions & 9 deletions dist/udb3-angular.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 41 additions & 6 deletions src/search/components/query-editor.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ function QueryEditorController(

console.log('queryFields', queryFields);

console.log('taxonomyTerms', taxonomyTerms);

qe.groupedQueryTree = searchHelper.getQueryTree() || qe.getDefaultQueryTree();

function getGroupsFromLuceneSyntax(query) {
Expand All @@ -99,6 +101,14 @@ function QueryEditorController(
return map;
}, {});


const fieldMappingByName = queryFields.filter(function(queryField) {
return !['startdate', 'enddate'].includes(queryField.name);
}).reduce(function(map, def) {
map[def.name] = def;
return map;
}, {});

function splitQuery(query) {
// Splitting the query by AND and OR, while keeping the separators
const parts = query.split(/ (AND|OR) /);
Expand Down Expand Up @@ -143,21 +153,44 @@ function QueryEditorController(

}

function getFieldNameForTermsId(id) {
const term = taxonomyTerms.find(function(term) {
return term.id === id;
});

if (term.domain === 'theme') {
return 'category_theme_name';
}

if (term.domain === 'facility') {
return 'category_facility_name';
}

if (term.domain === 'eventtype') {
return term.scope.includes('events') ? 'category_eventtype_name' : 'locationtype';
}
}

function parseQueryPart(part) {
console.log('part', part);
// Extract field and term from the part (assuming format "field:term")
const parts = part.split(':', 1);
console.log('parts', parts);
const field = parts[0].replace('(', '');
console.log('field', field);


const term = part.replace(field + ':', '').replaceAll('(', '').replaceAll(')', '');
console.log('term', term);

// Find the field definition in the mapping
const fieldDef = fieldMapping[field] || {};
// Implement parsing logic similar to the Python version
// This is a placeholder and needs to be adapted based on the query format and requirements
// ...
let fieldDef = fieldMapping[field] || {};

if (field === 'terms.id') {
const fieldName = getFieldNameForTermsId(term);
fieldDef = fieldMappingByName[fieldName] || {};
}


console.log('fieldDef', fieldDef);
console.log('fieldDef name', fieldDef.name);
Expand Down Expand Up @@ -198,10 +231,12 @@ function QueryEditorController(
}

// Example usage
const decodedQuery = 'dateRange:[2024-03-06T00:00:00+01:00 TO 2024-03-06T23:59:59+01:00] OR name.\\*:test';
// const decodedQuery = 'dateRange:[2024-03-06T00:00:00+01:00 TO 2024-03-06T23:59:59+01:00] OR name.\\*:test';
// name.\*:test OR (dateRange:[2024-03-07T00:00:00%2B01:00 TO *] OR (terms.id:1.7.1.0.0 OR audienceType:everyone))
// const decodedQuery = 'dateRange:[* TO 2024-03-07T23:59:59+01:00] OR name.\\*:test';
// const decodedQuery = 'name.\*:test OR (dateRange:[2024-03-07T00:00:00+01:00 TO *] OR (terms.id:3.14.0.0.0 OR audienceType:everyone))';
// const decodedQuery = 'name.\*:test OR (dateRange:[2024-03-07T00:00:00+01:00 TO *] OR (terms.id:3.14.0.0.0 OR audienceType:everyone))';
// const decodedQuery = 'terms.id:0.50.4.0.0 OR (location.labels:test OR (attendanceMode:mixed OR (bookingAvailability:available OR regions:nis-21004-Z)))';
const decodedQuery = 'terms.id:0.50.4.0.0 OR (location.labels:test OR (attendanceMode:mixed OR (bookingAvailability:available OR (terms.id:wwjRVmExI0w6xfQwT1KWpx OR (terms.id:1.7.12.0.0 OR terms.id:3.33.0.0.0)))))'

// TODO make multiple queries and write tests for it

Expand Down

0 comments on commit 76d5ea7

Please sign in to comment.