Skip to content
Closed
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Search user interface (UI) with Headless
lang: en
dateModified: 2025-02-24
dateModified: 2025-06-18
---

<p class="lead">This is a demo site for the GC Search UI.</p>
Expand Down Expand Up @@ -29,6 +29,8 @@ <h3>Advanced tests</h3>
<li><a href="test/budget.html">Budget sample</a></li>
<li><a href="test/gazette.html">Canada Gazette sample</a></li>
<li><a href="test/template.html">Custom summary and results templates</a></li>
<li><a href="test/newsadv-en.html">News Advanced Search user interface</a></li>
<li><a href="test/newsadv-fr.html">Interface utilisateur de la recherche avancée d'actualités</a></li>
</ul>

<hr>
Expand Down
63 changes: 61 additions & 2 deletions src/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ function initEngine() {

resultListController = buildResultList( headlessEngine, {
options: {
fieldsToInclude: [ "author", "date", "language", "urihash", "objecttype", "collection", "source", "permanentid", "displaynavlabel", "hostname" ]
fieldsToInclude: [ "author", "date", "language", "urihash", "objecttype", "collection", "source", "permanentid", "displaynavlabel", "hostname", "declared_type" ]
}
} );
querySummaryController = buildQuerySummary( headlessEngine );
Expand All @@ -485,7 +485,7 @@ function initEngine() {
statusController = buildSearchStatus( headlessEngine );

if ( urlParams.allq || urlParams.exctq || urlParams.anyq || urlParams.noneq || urlParams.fqupdate ||
urlParams.dmn || urlParams.fqocct || urlParams.elctn_cat || urlParams.filetype || urlParams.site || urlParams.year ) {
urlParams.dmn || urlParams.fqocct || urlParams.elctn_cat || urlParams.filetype || urlParams.site || urlParams.year || urlParams.declaredtype || urlParams.startdate || urlParams.enddate ) {
let q = [];
let qString = "";
if ( urlParams.allq ) {
Expand Down Expand Up @@ -622,6 +622,28 @@ function initEngine() {
let site = urlParams.site.toLowerCase().replace( '*', '' );
aqString += ' @canadagazettesite==' + site;
}

if ( urlParams.startdate && urlParams.enddate ) {
aqString += ' @date = "' + urlParams.startdate.replaceAll('-','/') + '..' + urlParams.enddate.replaceAll('-','/') + '"';
}
Comment on lines +626 to +628
Copy link
Contributor

Choose a reason for hiding this comment

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

@ipaksc Can you also include the cases where there would only be a startdate provided, and when there is only an enddate provided?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. i would
    replace
		if ( urlParams.startdate ) {
			aqString += ' @date = "' + urlParams.startdate.replaceAll('-','/') + '..' + currentDate() + '"';
		}

with

		if ( urlParams.startdate ) {
			aqString += ' @date >="' + urlParams.startdate.replaceAll('-','/')  + '"';
		}
  1. shouldn't the enddate be inclusuve
		if ( urlParams.enddate ) {
			aqString += ' @date  <=  "' + urlParams.enddate.replaceAll('-','/') + '"';
		}


if ( urlParams.startdate ) {
aqString += ' @date = "' + urlParams.startdate.replaceAll('-','/') + '..' + currentDate() + '"';
}

if ( urlParams.enddate ) {
aqString += ' @date < "' + urlParams.enddate.replaceAll('-','/') + '"';
}

if ( urlParams.dprtmnt ) {
aqString += ' @author = "' + urlParams.dprtmnt + '"';

}

if ( urlParams.declaredtype ) {
aqString += ' @declared_type="' + urlParams.declaredtype.replaceAll( /'/g, '&#39;' ) + '"';

}

if ( aqString ) {
const action = loadAdvancedSearchQueryActions( headlessEngine ).updateAdvancedSearchQueries( {
Expand Down Expand Up @@ -1151,6 +1173,10 @@ function updatePagerState( newState ) {

buttonNode.onclick = () => {
pagerController.previousPage();

if ( params.isAdvancedSearch ) {
updateUrlParameter( pagerState.currentPage );
}
};

pagerComponentElement.appendChild( liNode );
Expand Down Expand Up @@ -1178,6 +1204,10 @@ function updatePagerState( newState ) {

buttonNode.onclick = () => {
pagerController.selectPage( pageNo );

if ( params.isAdvancedSearch ) {
updateUrlParameter( pagerState.currentPage );
}
};

pagerComponentElement.appendChild( liNode );
Expand All @@ -1192,11 +1222,40 @@ function updatePagerState( newState ) {

buttonNode.onclick = () => {
pagerController.nextPage();

if ( params.isAdvancedSearch ) {
updateUrlParameter( pagerState.currentPage );
}
};

pagerComponentElement.appendChild( liNode );
}
}

function currentDate() {
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0');
var yyyy = today.getFullYear();

today = yyyy + "/" + mm + "/" + dd;

return today;
}

function updateUrlParameter(curtPage) {

const urlParams = new URLSearchParams(window.location.search);
const paramName = 'firstResult';
const pageNum = (curtPage - 1) * 10;

// Set the value of the parameter. If it doesn't exist, it will be added.
urlParams.set(paramName, pageNum);

const newSearch = urlParams.toString();
window.history.replaceState({}, '', `${window.location.pathname}?${newSearch}${window.location.hash}`);

}

// Run Search UI
initSearchUI();
Loading