PHRAS-676 #time 3h

new : returns facet on "type" (image, video, ...)
new : query on pseudo-field "type", ex:  "type:image"
This commit is contained in:
Jean-Yves Gaulier
2015-09-04 14:34:25 +02:00
parent 2643d697c2
commit e8f61a443b
7 changed files with 530 additions and 472 deletions

View File

@@ -29,6 +29,7 @@
// Rest
%token database database
%token collection collection
%token type type
%token id id|recordid
%token word [^\s()\[\]:<>≤≥=]+
@@ -55,6 +56,7 @@ ternary:
quaternary:
::database:: ::colon:: string() #database
| ::collection:: ::colon:: string() #collection
| ::type:: ::colon:: string() #type
| ::id:: ::colon:: string() #id
| quinary()
@@ -136,6 +138,7 @@ keyword:
| <or>
| <database>
| <collection>
| <type>
| <id>
symbol:

View File

@@ -0,0 +1,34 @@
<?php
namespace Alchemy\Phrasea\SearchEngine\Elastic\AST;
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContext;
class TypeExpression extends Node
{
private $typeName;
public function __construct($typeName)
{
$this->typeName = $typeName;
}
public function buildQuery(QueryContext $context)
{
return [
'term' => [
'type' => $this->typeName
]
];
}
public function getTermNodes()
{
return array();
}
public function __toString()
{
return sprintf('<type:%s>', $this->typeName);
}
}

View File

@@ -444,6 +444,11 @@ class ElasticSearchEngine implements SearchEngineInterface
$base_facet_agg['terms']['field'] = 'databox_name';
$aggs['Base'] = $base_facet_agg;
// We always want a type facet right now
$base_facet_agg = array();
$base_facet_agg['terms']['field'] = 'type';
$aggs['Type'] = $base_facet_agg;
$structure = $this->getLimitedStructure($options);
foreach ($structure->getFacetFields() as $name => $field) {
// 2015-05-26 (mdarse) Removed databox filtering.

View File

@@ -75,6 +75,8 @@ class FacetsResponse implements JsonSerializable
return sprintf('collection:%s', $this->escaper->escapeWord($value));
case 'Base':
return sprintf('database:%s', $this->escaper->escapeWord($value));
case 'Type':
return sprintf('type:%s', $this->escaper->escapeWord($value));
default:
return sprintf('r"%s" IN %s', $this->escaper->escapeRaw($value), $name);
}

View File

@@ -22,6 +22,7 @@ class NodeTypes
const TEXT = '#text';
const CONTEXT = '#context';
const COLLECTION = '#collection';
const TYPE = '#type';
const DATABASE = '#database';
const IDENTIFIER = '#id';
// Token types for leaf nodes

View File

@@ -88,6 +88,9 @@ class QueryVisitor implements Visit
case NodeTypes::COLLECTION:
return $this->visitCollectionNode($element);
case NodeTypes::TYPE:
return $this->visitTypeNode($element);
case NodeTypes::IDENTIFIER:
return $this->visitIdentifierNode($element);
@@ -279,6 +282,16 @@ class QueryVisitor implements Visit
return new AST\CollectionExpression($collectionName);
}
private function visitTypeNode(Element $element)
{
if ($element->getChildrenNumber() !== 1) {
throw new \Exception('Type filter can only have a single child.');
}
$typeName = $element->getChild(0)->getValue()['value'];
return new AST\TypeExpression($typeName);
}
private function visitIdentifierNode(Element $element)
{
if ($element->getChildrenNumber() !== 1) {