mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +00:00
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:
@@ -29,6 +29,7 @@
|
|||||||
// Rest
|
// Rest
|
||||||
%token database database
|
%token database database
|
||||||
%token collection collection
|
%token collection collection
|
||||||
|
%token type type
|
||||||
%token id id|recordid
|
%token id id|recordid
|
||||||
%token word [^\s()\[\]:<>≤≥=]+
|
%token word [^\s()\[\]:<>≤≥=]+
|
||||||
|
|
||||||
@@ -55,6 +56,7 @@ ternary:
|
|||||||
quaternary:
|
quaternary:
|
||||||
::database:: ::colon:: string() #database
|
::database:: ::colon:: string() #database
|
||||||
| ::collection:: ::colon:: string() #collection
|
| ::collection:: ::colon:: string() #collection
|
||||||
|
| ::type:: ::colon:: string() #type
|
||||||
| ::id:: ::colon:: string() #id
|
| ::id:: ::colon:: string() #id
|
||||||
| quinary()
|
| quinary()
|
||||||
|
|
||||||
@@ -136,6 +138,7 @@ keyword:
|
|||||||
| <or>
|
| <or>
|
||||||
| <database>
|
| <database>
|
||||||
| <collection>
|
| <collection>
|
||||||
|
| <type>
|
||||||
| <id>
|
| <id>
|
||||||
|
|
||||||
symbol:
|
symbol:
|
||||||
|
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
@@ -444,6 +444,11 @@ class ElasticSearchEngine implements SearchEngineInterface
|
|||||||
$base_facet_agg['terms']['field'] = 'databox_name';
|
$base_facet_agg['terms']['field'] = 'databox_name';
|
||||||
$aggs['Base'] = $base_facet_agg;
|
$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);
|
$structure = $this->getLimitedStructure($options);
|
||||||
foreach ($structure->getFacetFields() as $name => $field) {
|
foreach ($structure->getFacetFields() as $name => $field) {
|
||||||
// 2015-05-26 (mdarse) Removed databox filtering.
|
// 2015-05-26 (mdarse) Removed databox filtering.
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -75,6 +75,8 @@ class FacetsResponse implements JsonSerializable
|
|||||||
return sprintf('collection:%s', $this->escaper->escapeWord($value));
|
return sprintf('collection:%s', $this->escaper->escapeWord($value));
|
||||||
case 'Base':
|
case 'Base':
|
||||||
return sprintf('database:%s', $this->escaper->escapeWord($value));
|
return sprintf('database:%s', $this->escaper->escapeWord($value));
|
||||||
|
case 'Type':
|
||||||
|
return sprintf('type:%s', $this->escaper->escapeWord($value));
|
||||||
default:
|
default:
|
||||||
return sprintf('r"%s" IN %s', $this->escaper->escapeRaw($value), $name);
|
return sprintf('r"%s" IN %s', $this->escaper->escapeRaw($value), $name);
|
||||||
}
|
}
|
||||||
|
@@ -22,6 +22,7 @@ class NodeTypes
|
|||||||
const TEXT = '#text';
|
const TEXT = '#text';
|
||||||
const CONTEXT = '#context';
|
const CONTEXT = '#context';
|
||||||
const COLLECTION = '#collection';
|
const COLLECTION = '#collection';
|
||||||
|
const TYPE = '#type';
|
||||||
const DATABASE = '#database';
|
const DATABASE = '#database';
|
||||||
const IDENTIFIER = '#id';
|
const IDENTIFIER = '#id';
|
||||||
// Token types for leaf nodes
|
// Token types for leaf nodes
|
||||||
|
@@ -88,6 +88,9 @@ class QueryVisitor implements Visit
|
|||||||
case NodeTypes::COLLECTION:
|
case NodeTypes::COLLECTION:
|
||||||
return $this->visitCollectionNode($element);
|
return $this->visitCollectionNode($element);
|
||||||
|
|
||||||
|
case NodeTypes::TYPE:
|
||||||
|
return $this->visitTypeNode($element);
|
||||||
|
|
||||||
case NodeTypes::IDENTIFIER:
|
case NodeTypes::IDENTIFIER:
|
||||||
return $this->visitIdentifierNode($element);
|
return $this->visitIdentifierNode($element);
|
||||||
|
|
||||||
@@ -279,6 +282,16 @@ class QueryVisitor implements Visit
|
|||||||
return new AST\CollectionExpression($collectionName);
|
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)
|
private function visitIdentifierNode(Element $element)
|
||||||
{
|
{
|
||||||
if ($element->getChildrenNumber() !== 1) {
|
if ($element->getChildrenNumber() !== 1) {
|
||||||
|
Reference in New Issue
Block a user