filtering works
authorChristian Weiske <cweiske@cweiske.de>
Wed, 3 Feb 2016 16:23:06 +0000 (17:23 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 3 Feb 2016 16:23:06 +0000 (17:23 +0100)
data/templates/search/hit.htm
data/templates/search/sidebar-filter.htm [new file with mode: 0644]
data/templates/search/sidebar.htm
www/css/phinde.css
www/index.php
www/www-header.php

index 3d8f633e1c58bf3603d558637bbf4fb1f3d01461..4981017628431eff863ffe79fceda654c5e8aba1 100644 (file)
@@ -1,11 +1,23 @@
 {% set doc = hit._source %}
 <li class="hit">
 {% set doc = hit._source %}
 <li class="hit">
- <a href="{{doc.url}}">{{doc.title}}</a>
- {% if doc.author.name %}
- by <a href="{{doc.author.url}}">{{doc.author.name}}</a>
- {% endif %}
- <br/><tt>{{doc.extra.cleanUrl}}</tt>
- {% if doc.modate %}
- <br/>Changed: {{doc.extra.day}}
- {% endif %}
+ <span class="title">
+  <a href="{{doc.url}}">{{doc.title}}</a>
+  {% if doc.author.name %}
+  by
+  <em>
+   {% if doc.author.url %}
+   <a href="{{doc.author.url}}">{{doc.author.name}}</a>
+   {% else %}
+   {{doc.author.name}}
+   {% endif %}
+  </em>
+  {% endif %}
+ </span>
+ <br/><tt class="url" title="{{doc.extra.cleanUrl}}">{{ellipsis(doc.extra.cleanUrl, 60)}}</tt>
+ <span class="extract">
+  <br/>
+  {% if doc.modate %}
+  <span class="date">{{doc.extra.day|date("Y-m-d")}}</span>
+  {% endif %}
+ </span>
 </li>
 </li>
diff --git a/data/templates/search/sidebar-filter.htm b/data/templates/search/sidebar-filter.htm
new file mode 100644 (file)
index 0000000..6c4bc81
--- /dev/null
@@ -0,0 +1,21 @@
+{% if attribute(activeFilters, type) %}
+ <b>{{title}}</b>
+ <ul class="nav nav-pills">
+  <li class="active">
+   <a href="{{attribute(activeFilters, type).removeUrl}}">
+    {{activeFilters[type].label|default('unknown')}} ❌
+   </a>
+  </li>
+ </ul>
+{% elseif attribute(aggregations, type).buckets|length > 1 %}
+<b>{{title}}</b>
+<ul class="nav nav-pills">
+{% for bucket in attribute(aggregations, type).buckets|slice(0, 10) %}
+ <li>
+  <a href="{{bucket.url}}">
+   {{bucket.key|default('unknown')}} ({{bucket.doc_count}})
+  </a>
+ </li>
+{% endfor %}
+</ul>
+{% endif %}
index 619301e11fc354d2cfc5b3872b7707a74559b916..eaddaeb9ad5fea76bb132aca0bc4c9fcccf45483 100644 (file)
@@ -1,48 +1,7 @@
 <p>
  Filter results by:
 </p>
 <p>
  Filter results by:
 </p>
-{% if aggregations.tags.buckets|length > 1 %}
-<b>Tag</b>
-<ul class="nav nav-pills">
-{% for bucket in aggregations.tags.buckets|slice(0, 10) %}
- <li>
-  <a href="{{bucket.url}}">{{bucket.key}} ({{bucket.doc_count}})</a>
- </li>
-{% endfor %}
-</ul>
-{% endif %}
-
-{% if aggregations.domain.buckets|length > 1 %}
-<!-- FIXME: negate domain -->
-<b>Domain</b>
-<ul class="nav nav-pills">
-{% for bucket in aggregations.domain.buckets|slice(0, 10) %}
- <li>
-  <a href="{{bucket.url}}">{{bucket.key}} ({{bucket.doc_count}})</a>
- </li>
-{% endfor %}
-</ul>
-{% endif %}
-
-{% if aggregations.language.buckets|length > 1 %}
-<b>Language</b>
-<ul class="nav nav-pills">
-{% for bucket in aggregations.language.buckets|slice(0, 10) %}
- <li>
-  <a href="{{bucket.url}}">{{bucket.key}} ({{bucket.doc_count}})</a>
- </li>
-{% endfor %}
-</ul>
-{% endif %}
-
-{% if aggregations.type.buckets|length > 1 %}
-<b>Type</b>
-<ul class="nav nav-pills">
-{% for bucket in aggregations.type.buckets|slice(0, 10) %}
- <li>
-  <a href="{{bucket.url}}">{{bucket.key}} ({{bucket.doc_count}})</a>
- </li>
-{% endfor %}
-</ul>
-{% endif %}
-
+{% include 'search/sidebar-filter.htm' with {'type': 'tags', 'title': 'Tag'} %}
+{% include 'search/sidebar-filter.htm' with {'type': 'domain', 'title': 'Domain'} %}
+{% include 'search/sidebar-filter.htm' with {'type': 'language', 'title': 'Language'} %}
+{% include 'search/sidebar-filter.htm' with {'type': 'type', 'title': 'Type'} %}
index 1e34fcf4203a1a2e7fdd0febc1e9ad8a615afbc5..a3d593ed0480fa742194e5c6d0cd034ea26063f7 100644 (file)
 }
 .hit {
     margin-bottom: 2ex;
 }
 .hit {
     margin-bottom: 2ex;
+}
+.hit .title {
+    font-size: 120%;
+}
+.hit .url {
+    color: #070;
+}
+.hit .extract {
+    font-size: 95%;
+}
+.hit .date {
+    color: #666;
 }
\ No newline at end of file
 }
\ No newline at end of file
index 8cdca41b9b4928f4665aae7142869487bbd84a3e..257ad87c99ec7c5a92dac9e57e1590ad09f2eeab 100644 (file)
@@ -18,6 +18,8 @@ if (isset($_GET['page'])) {
 }
 $perPage = 10;//$GLOBALS['phinde']['perPage'];
 
 }
 $perPage = 10;//$GLOBALS['phinde']['perPage'];
 
+$baseLink = '?q=' . urlencode($query);
+
 $filters = array();
 if (isset($_GET['filter'])) {
     $allowedFilter = array('domain', 'language', 'tags', 'term');
 $filters = array();
 if (isset($_GET['filter'])) {
     $allowedFilter = array('domain', 'language', 'tags', 'term');
@@ -27,13 +29,37 @@ if (isset($_GET['filter'])) {
         }
     }
 }
         }
     }
 }
+$activeFilters = array();
+foreach ($filters as $type => $value) {
+    $activeFilters[$type] = array(
+        'label' => $value,
+        'removeUrl' => buildLink($baseLink, $filters, $type, null),
+    );
+}
+
+function buildLink($baseLink, $filters, $addFilterType, $addFilterValue)
+{
+    if ($addFilterValue === null) {
+        if (array_key_exists($addFilterType, $filters)) {
+            unset($filters[$addFilterType]);
+        }
+    } else {
+        $filters[$addFilterType] = $addFilterValue;
+    }
+
+    $params = http_build_query(array('filter' => $filters));
+    if (strlen($params)) {
+        return $baseLink . '&' . $params;
+    }
+    return $baseLink;
+}
 
 $es = new Elasticsearch($GLOBALS['phinde']['elasticsearch']);
 $res = $es->search($query, $filters, $page, $perPage);
 
 $pager = new Html_Pager(
     $res->hits->total, $perPage, $page + 1,
 
 $es = new Elasticsearch($GLOBALS['phinde']['elasticsearch']);
 $res = $es->search($query, $filters, $page, $perPage);
 
 $pager = new Html_Pager(
     $res->hits->total, $perPage, $page + 1,
-    '?q=' . $query
+    $baseLink
 );
 
 foreach ($res->hits->hits as &$hit) {
 );
 
 foreach ($res->hits->hits as &$hit) {
@@ -48,11 +74,9 @@ foreach ($res->hits->hits as &$hit) {
     }
 }
 
     }
 }
 
-$baseLink = '?q=' . urlencode($query);
 foreach ($res->aggregations as $key => &$aggregation) {
     foreach ($aggregation->buckets as &$bucket) {
 foreach ($res->aggregations as $key => &$aggregation) {
     foreach ($aggregation->buckets as &$bucket) {
-        $bucket->url = $baseLink
-            . '&filter[' . urlencode($key) . ']=' . urlencode($bucket->key);
+        $bucket->url = buildLink($baseLink, $filters, $key, $bucket->key);
     }
 }
 //var_dump($res->aggregations);
     }
 }
 //var_dump($res->aggregations);
@@ -64,6 +88,7 @@ render(
         'hitcount' => $res->hits->total,
         'hits' => $res->hits->hits,
         'aggregations' => $res->aggregations,
         'hitcount' => $res->hits->total,
         'hits' => $res->hits->hits,
         'aggregations' => $res->aggregations,
+        'activeFilters' => $activeFilters,
         'pager' => $pager
     )
 );
         'pager' => $pager
     )
 );
index 60adacf2c5109051a002f005d992ae46b8be9710..2ec8c2fffcc876e464247031af340f88ab0aeb9c 100644 (file)
@@ -12,6 +12,14 @@ $GLOBALS['twig'] = new \Twig_Environment(
 );
 $GLOBALS['twig']->addExtension(new \Twig_Extension_Debug());
 
 );
 $GLOBALS['twig']->addExtension(new \Twig_Extension_Debug());
 
+$twig->addFunction('ellipsis', new \Twig_Function_Function('\phinde\ellipsis'));
+function ellipsis($text, $maxlength)
+{
+    if (strlen($text) > $maxlength) {
+        $text = substr($text, 0, $maxlength - 1) . '…';
+    }
+    return $text;
+}
 
 function render($tplname, $vars = array(), $return = false)
 {
 
 function render($tplname, $vars = array(), $return = false)
 {