From 8c214105e8e9b7558e37bb3e9bcc491934516247 Mon Sep 17 00:00:00 2001
From: esikkala <esko.ikkala@aalto.fi>
Date: Wed, 19 Jun 2019 16:00:00 +0300
Subject: [PATCH] Timespan filter: either start or end is in selected range

---
 src/server/sparql/Filters.js | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/server/sparql/Filters.js b/src/server/sparql/Filters.js
index 1f404e47..0fcb2ae4 100644
--- a/src/server/sparql/Filters.js
+++ b/src/server/sparql/Filters.js
@@ -50,12 +50,26 @@ export const generateFilter = ({
       if (property !== facetProperty) {
         const facetConfig = facetConfigs[facetClass][property];
         const { start, end } = timespanFilters[property];
+        const selectionStart = start;
+        const selectionEnd = end;
+        // filterStr += `
+        //   ?${filterTarget} ${facetConfig.predicate} ?timespan .
+        //   ?timespan ${facetConfig.startProperty} ?start .
+        //   ?timespan ${facetConfig.endProperty} ?end .
+        //   # both start and end is included in selected range
+        //   FILTER(?start >= "${start}"^^xsd:date)
+        //   FILTER(?end <= "${end}"^^xsd:date)
+        // `;
         filterStr += `
           ?${filterTarget} ${facetConfig.predicate} ?timespan .
-          ?timespan ${facetConfig.startProperty} ?start .
-          ?timespan ${facetConfig.endProperty} ?end .
-          FILTER(?start >= "${start}"^^xsd:date)
-          FILTER(?end <= "${end}"^^xsd:date)
+          ?timespan ${facetConfig.startProperty} ?timespanStart .
+          ?timespan ${facetConfig.endProperty} ?timespanEnd .
+          # either start or end is included in the selected range
+          FILTER(
+            ?timespanStart >= "${selectionStart}"^^xsd:date && ?timespanStart <= "${selectionEnd}"^^xsd:date
+            ||
+            ?timespanEnd >= "${selectionStart}"^^xsd:date && ?timespanEnd <= "${selectionEnd}"^^xsd:date
+          )
         `;
       }
     }
-- 
GitLab