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 // 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:

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'; $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.

View File

@@ -29,411 +29,411 @@ class QueryParser
{ {
//Setup Parser //Setup Parser
$symbol0 = new ParserSymbol("accept", 0); $symbol0 = new ParserSymbol("accept", 0);
$symbol1 = new ParserSymbol("end", 1); $symbol1 = new ParserSymbol("end", 1);
$symbol2 = new ParserSymbol("error", 2); $symbol2 = new ParserSymbol("error", 2);
$symbol3 = new ParserSymbol("query", 3); $symbol3 = new ParserSymbol("query", 3);
$symbol4 = new ParserSymbol("expressions", 4); $symbol4 = new ParserSymbol("expressions", 4);
$symbol5 = new ParserSymbol("EOF", 5); $symbol5 = new ParserSymbol("EOF", 5);
$symbol6 = new ParserSymbol("expression", 6); $symbol6 = new ParserSymbol("expression", 6);
$symbol7 = new ParserSymbol("AND", 7); $symbol7 = new ParserSymbol("AND", 7);
$symbol8 = new ParserSymbol("OR", 8); $symbol8 = new ParserSymbol("OR", 8);
$symbol9 = new ParserSymbol("IN", 9); $symbol9 = new ParserSymbol("IN", 9);
$symbol10 = new ParserSymbol("keyword", 10); $symbol10 = new ParserSymbol("keyword", 10);
$symbol11 = new ParserSymbol("(", 11); $symbol11 = new ParserSymbol("(", 11);
$symbol12 = new ParserSymbol(")", 12); $symbol12 = new ParserSymbol(")", 12);
$symbol13 = new ParserSymbol("prefix", 13); $symbol13 = new ParserSymbol("prefix", 13);
$symbol14 = new ParserSymbol("text", 14); $symbol14 = new ParserSymbol("text", 14);
$symbol15 = new ParserSymbol("WORD", 15); $symbol15 = new ParserSymbol("WORD", 15);
$symbol16 = new ParserSymbol("*", 16); $symbol16 = new ParserSymbol("*", 16);
$symbol17 = new ParserSymbol("LITERAL", 17); $symbol17 = new ParserSymbol("LITERAL", 17);
$this->symbols[0] = $symbol0; $this->symbols[0] = $symbol0;
$this->symbols["accept"] = $symbol0; $this->symbols["accept"] = $symbol0;
$this->symbols[1] = $symbol1; $this->symbols[1] = $symbol1;
$this->symbols["end"] = $symbol1; $this->symbols["end"] = $symbol1;
$this->symbols[2] = $symbol2; $this->symbols[2] = $symbol2;
$this->symbols["error"] = $symbol2; $this->symbols["error"] = $symbol2;
$this->symbols[3] = $symbol3; $this->symbols[3] = $symbol3;
$this->symbols["query"] = $symbol3; $this->symbols["query"] = $symbol3;
$this->symbols[4] = $symbol4; $this->symbols[4] = $symbol4;
$this->symbols["expressions"] = $symbol4; $this->symbols["expressions"] = $symbol4;
$this->symbols[5] = $symbol5; $this->symbols[5] = $symbol5;
$this->symbols["EOF"] = $symbol5; $this->symbols["EOF"] = $symbol5;
$this->symbols[6] = $symbol6; $this->symbols[6] = $symbol6;
$this->symbols["expression"] = $symbol6; $this->symbols["expression"] = $symbol6;
$this->symbols[7] = $symbol7; $this->symbols[7] = $symbol7;
$this->symbols["AND"] = $symbol7; $this->symbols["AND"] = $symbol7;
$this->symbols[8] = $symbol8; $this->symbols[8] = $symbol8;
$this->symbols["OR"] = $symbol8; $this->symbols["OR"] = $symbol8;
$this->symbols[9] = $symbol9; $this->symbols[9] = $symbol9;
$this->symbols["IN"] = $symbol9; $this->symbols["IN"] = $symbol9;
$this->symbols[10] = $symbol10; $this->symbols[10] = $symbol10;
$this->symbols["keyword"] = $symbol10; $this->symbols["keyword"] = $symbol10;
$this->symbols[11] = $symbol11; $this->symbols[11] = $symbol11;
$this->symbols["("] = $symbol11; $this->symbols["("] = $symbol11;
$this->symbols[12] = $symbol12; $this->symbols[12] = $symbol12;
$this->symbols[")"] = $symbol12; $this->symbols[")"] = $symbol12;
$this->symbols[13] = $symbol13; $this->symbols[13] = $symbol13;
$this->symbols["prefix"] = $symbol13; $this->symbols["prefix"] = $symbol13;
$this->symbols[14] = $symbol14; $this->symbols[14] = $symbol14;
$this->symbols["text"] = $symbol14; $this->symbols["text"] = $symbol14;
$this->symbols[15] = $symbol15; $this->symbols[15] = $symbol15;
$this->symbols["WORD"] = $symbol15; $this->symbols["WORD"] = $symbol15;
$this->symbols[16] = $symbol16; $this->symbols[16] = $symbol16;
$this->symbols["*"] = $symbol16; $this->symbols["*"] = $symbol16;
$this->symbols[17] = $symbol17; $this->symbols[17] = $symbol17;
$this->symbols["LITERAL"] = $symbol17; $this->symbols["LITERAL"] = $symbol17;
$this->terminals = array( $this->terminals = array(
2=>&$symbol2, 2=>&$symbol2,
5=>&$symbol5, 5=>&$symbol5,
7=>&$symbol7, 7=>&$symbol7,
8=>&$symbol8, 8=>&$symbol8,
9=>&$symbol9, 9=>&$symbol9,
11=>&$symbol11, 11=>&$symbol11,
12=>&$symbol12, 12=>&$symbol12,
15=>&$symbol15, 15=>&$symbol15,
16=>&$symbol16, 16=>&$symbol16,
17=>&$symbol17 17=>&$symbol17
); );
$table0 = new ParserState(0); $table0 = new ParserState(0);
$table1 = new ParserState(1); $table1 = new ParserState(1);
$table2 = new ParserState(2); $table2 = new ParserState(2);
$table3 = new ParserState(3); $table3 = new ParserState(3);
$table4 = new ParserState(4); $table4 = new ParserState(4);
$table5 = new ParserState(5); $table5 = new ParserState(5);
$table6 = new ParserState(6); $table6 = new ParserState(6);
$table7 = new ParserState(7); $table7 = new ParserState(7);
$table8 = new ParserState(8); $table8 = new ParserState(8);
$table9 = new ParserState(9); $table9 = new ParserState(9);
$table10 = new ParserState(10); $table10 = new ParserState(10);
$table11 = new ParserState(11); $table11 = new ParserState(11);
$table12 = new ParserState(12); $table12 = new ParserState(12);
$table13 = new ParserState(13); $table13 = new ParserState(13);
$table14 = new ParserState(14); $table14 = new ParserState(14);
$table15 = new ParserState(15); $table15 = new ParserState(15);
$table16 = new ParserState(16); $table16 = new ParserState(16);
$table17 = new ParserState(17); $table17 = new ParserState(17);
$table18 = new ParserState(18); $table18 = new ParserState(18);
$table19 = new ParserState(19); $table19 = new ParserState(19);
$table20 = new ParserState(20); $table20 = new ParserState(20);
$tableDefinition0 = array( $tableDefinition0 = array(
3=>new ParserAction($this->none, $table1), 3=>new ParserAction($this->none, $table1),
4=>new ParserAction($this->none, $table2), 4=>new ParserAction($this->none, $table2),
6=>new ParserAction($this->none, $table3), 6=>new ParserAction($this->none, $table3),
11=>new ParserAction($this->shift, $table4), 11=>new ParserAction($this->shift, $table4),
13=>new ParserAction($this->none, $table5), 13=>new ParserAction($this->none, $table5),
14=>new ParserAction($this->none, $table6), 14=>new ParserAction($this->none, $table6),
15=>new ParserAction($this->shift, $table7), 15=>new ParserAction($this->shift, $table7),
17=>new ParserAction($this->shift, $table8) 17=>new ParserAction($this->shift, $table8)
); );
$tableDefinition1 = array( $tableDefinition1 = array(
1=>new ParserAction($this->accept) 1=>new ParserAction($this->accept)
); );
$tableDefinition2 = array( $tableDefinition2 = array(
5=>new ParserAction($this->shift, $table9) 5=>new ParserAction($this->shift, $table9)
); );
$tableDefinition3 = array( $tableDefinition3 = array(
4=>new ParserAction($this->none, $table10), 4=>new ParserAction($this->none, $table10),
5=>new ParserAction($this->reduce, $table3), 5=>new ParserAction($this->reduce, $table3),
6=>new ParserAction($this->none, $table3), 6=>new ParserAction($this->none, $table3),
7=>new ParserAction($this->shift, $table11), 7=>new ParserAction($this->shift, $table11),
8=>new ParserAction($this->shift, $table12), 8=>new ParserAction($this->shift, $table12),
9=>new ParserAction($this->shift, $table13), 9=>new ParserAction($this->shift, $table13),
11=>new ParserAction($this->shift, $table4), 11=>new ParserAction($this->shift, $table4),
13=>new ParserAction($this->none, $table5), 13=>new ParserAction($this->none, $table5),
14=>new ParserAction($this->none, $table6), 14=>new ParserAction($this->none, $table6),
15=>new ParserAction($this->shift, $table7), 15=>new ParserAction($this->shift, $table7),
17=>new ParserAction($this->shift, $table8) 17=>new ParserAction($this->shift, $table8)
); );
$tableDefinition4 = array( $tableDefinition4 = array(
6=>new ParserAction($this->none, $table14), 6=>new ParserAction($this->none, $table14),
11=>new ParserAction($this->shift, $table4), 11=>new ParserAction($this->shift, $table4),
13=>new ParserAction($this->none, $table5), 13=>new ParserAction($this->none, $table5),
14=>new ParserAction($this->none, $table6), 14=>new ParserAction($this->none, $table6),
15=>new ParserAction($this->shift, $table7), 15=>new ParserAction($this->shift, $table7),
17=>new ParserAction($this->shift, $table8) 17=>new ParserAction($this->shift, $table8)
); );
$tableDefinition5 = array( $tableDefinition5 = array(
5=>new ParserAction($this->reduce, $table8), 5=>new ParserAction($this->reduce, $table8),
7=>new ParserAction($this->reduce, $table8), 7=>new ParserAction($this->reduce, $table8),
8=>new ParserAction($this->reduce, $table8), 8=>new ParserAction($this->reduce, $table8),
9=>new ParserAction($this->reduce, $table8), 9=>new ParserAction($this->reduce, $table8),
11=>new ParserAction($this->reduce, $table8), 11=>new ParserAction($this->reduce, $table8),
12=>new ParserAction($this->reduce, $table8), 12=>new ParserAction($this->reduce, $table8),
15=>new ParserAction($this->reduce, $table8), 15=>new ParserAction($this->reduce, $table8),
17=>new ParserAction($this->reduce, $table8) 17=>new ParserAction($this->reduce, $table8)
); );
$tableDefinition6 = array( $tableDefinition6 = array(
5=>new ParserAction($this->reduce, $table9), 5=>new ParserAction($this->reduce, $table9),
7=>new ParserAction($this->reduce, $table9), 7=>new ParserAction($this->reduce, $table9),
8=>new ParserAction($this->reduce, $table9), 8=>new ParserAction($this->reduce, $table9),
9=>new ParserAction($this->reduce, $table9), 9=>new ParserAction($this->reduce, $table9),
11=>new ParserAction($this->reduce, $table9), 11=>new ParserAction($this->reduce, $table9),
12=>new ParserAction($this->reduce, $table9), 12=>new ParserAction($this->reduce, $table9),
15=>new ParserAction($this->reduce, $table9), 15=>new ParserAction($this->reduce, $table9),
17=>new ParserAction($this->reduce, $table9) 17=>new ParserAction($this->reduce, $table9)
); );
$tableDefinition7 = array( $tableDefinition7 = array(
5=>new ParserAction($this->reduce, $table12), 5=>new ParserAction($this->reduce, $table12),
7=>new ParserAction($this->reduce, $table12), 7=>new ParserAction($this->reduce, $table12),
8=>new ParserAction($this->reduce, $table12), 8=>new ParserAction($this->reduce, $table12),
9=>new ParserAction($this->reduce, $table12), 9=>new ParserAction($this->reduce, $table12),
11=>new ParserAction($this->reduce, $table12), 11=>new ParserAction($this->reduce, $table12),
12=>new ParserAction($this->reduce, $table12), 12=>new ParserAction($this->reduce, $table12),
15=>new ParserAction($this->reduce, $table12), 15=>new ParserAction($this->reduce, $table12),
16=>new ParserAction($this->shift, $table15), 16=>new ParserAction($this->shift, $table15),
17=>new ParserAction($this->reduce, $table12) 17=>new ParserAction($this->reduce, $table12)
); );
$tableDefinition8 = array( $tableDefinition8 = array(
5=>new ParserAction($this->reduce, $table13), 5=>new ParserAction($this->reduce, $table13),
7=>new ParserAction($this->reduce, $table13), 7=>new ParserAction($this->reduce, $table13),
8=>new ParserAction($this->reduce, $table13), 8=>new ParserAction($this->reduce, $table13),
9=>new ParserAction($this->reduce, $table13), 9=>new ParserAction($this->reduce, $table13),
11=>new ParserAction($this->reduce, $table13), 11=>new ParserAction($this->reduce, $table13),
12=>new ParserAction($this->reduce, $table13), 12=>new ParserAction($this->reduce, $table13),
15=>new ParserAction($this->reduce, $table13), 15=>new ParserAction($this->reduce, $table13),
17=>new ParserAction($this->reduce, $table13) 17=>new ParserAction($this->reduce, $table13)
); );
$tableDefinition9 = array( $tableDefinition9 = array(
1=>new ParserAction($this->reduce, $table1) 1=>new ParserAction($this->reduce, $table1)
); );
$tableDefinition10 = array( $tableDefinition10 = array(
5=>new ParserAction($this->reduce, $table2) 5=>new ParserAction($this->reduce, $table2)
); );
$tableDefinition11 = array( $tableDefinition11 = array(
6=>new ParserAction($this->none, $table16), 6=>new ParserAction($this->none, $table16),
11=>new ParserAction($this->shift, $table4), 11=>new ParserAction($this->shift, $table4),
13=>new ParserAction($this->none, $table5), 13=>new ParserAction($this->none, $table5),
14=>new ParserAction($this->none, $table6), 14=>new ParserAction($this->none, $table6),
15=>new ParserAction($this->shift, $table7), 15=>new ParserAction($this->shift, $table7),
17=>new ParserAction($this->shift, $table8) 17=>new ParserAction($this->shift, $table8)
); );
$tableDefinition12 = array( $tableDefinition12 = array(
6=>new ParserAction($this->none, $table17), 6=>new ParserAction($this->none, $table17),
11=>new ParserAction($this->shift, $table4), 11=>new ParserAction($this->shift, $table4),
13=>new ParserAction($this->none, $table5), 13=>new ParserAction($this->none, $table5),
14=>new ParserAction($this->none, $table6), 14=>new ParserAction($this->none, $table6),
15=>new ParserAction($this->shift, $table7), 15=>new ParserAction($this->shift, $table7),
17=>new ParserAction($this->shift, $table8) 17=>new ParserAction($this->shift, $table8)
); );
$tableDefinition13 = array( $tableDefinition13 = array(
10=>new ParserAction($this->none, $table18), 10=>new ParserAction($this->none, $table18),
15=>new ParserAction($this->shift, $table19) 15=>new ParserAction($this->shift, $table19)
); );
$tableDefinition14 = array( $tableDefinition14 = array(
7=>new ParserAction($this->shift, $table11), 7=>new ParserAction($this->shift, $table11),
8=>new ParserAction($this->shift, $table12), 8=>new ParserAction($this->shift, $table12),
9=>new ParserAction($this->shift, $table13), 9=>new ParserAction($this->shift, $table13),
12=>new ParserAction($this->shift, $table20) 12=>new ParserAction($this->shift, $table20)
); );
$tableDefinition15 = array( $tableDefinition15 = array(
5=>new ParserAction($this->reduce, $table11), 5=>new ParserAction($this->reduce, $table11),
7=>new ParserAction($this->reduce, $table11), 7=>new ParserAction($this->reduce, $table11),
8=>new ParserAction($this->reduce, $table11), 8=>new ParserAction($this->reduce, $table11),
9=>new ParserAction($this->reduce, $table11), 9=>new ParserAction($this->reduce, $table11),
11=>new ParserAction($this->reduce, $table11), 11=>new ParserAction($this->reduce, $table11),
12=>new ParserAction($this->reduce, $table11), 12=>new ParserAction($this->reduce, $table11),
15=>new ParserAction($this->reduce, $table11), 15=>new ParserAction($this->reduce, $table11),
17=>new ParserAction($this->reduce, $table11) 17=>new ParserAction($this->reduce, $table11)
); );
$tableDefinition16 = array( $tableDefinition16 = array(
5=>new ParserAction($this->reduce, $table4), 5=>new ParserAction($this->reduce, $table4),
7=>new ParserAction($this->reduce, $table4), 7=>new ParserAction($this->reduce, $table4),
8=>new ParserAction($this->reduce, $table4), 8=>new ParserAction($this->reduce, $table4),
9=>new ParserAction($this->shift, $table13), 9=>new ParserAction($this->shift, $table13),
11=>new ParserAction($this->reduce, $table4), 11=>new ParserAction($this->reduce, $table4),
12=>new ParserAction($this->reduce, $table4), 12=>new ParserAction($this->reduce, $table4),
15=>new ParserAction($this->reduce, $table4), 15=>new ParserAction($this->reduce, $table4),
17=>new ParserAction($this->reduce, $table4) 17=>new ParserAction($this->reduce, $table4)
); );
$tableDefinition17 = array( $tableDefinition17 = array(
5=>new ParserAction($this->reduce, $table5), 5=>new ParserAction($this->reduce, $table5),
7=>new ParserAction($this->reduce, $table5), 7=>new ParserAction($this->reduce, $table5),
8=>new ParserAction($this->reduce, $table5), 8=>new ParserAction($this->reduce, $table5),
9=>new ParserAction($this->shift, $table13), 9=>new ParserAction($this->shift, $table13),
11=>new ParserAction($this->reduce, $table5), 11=>new ParserAction($this->reduce, $table5),
12=>new ParserAction($this->reduce, $table5), 12=>new ParserAction($this->reduce, $table5),
15=>new ParserAction($this->reduce, $table5), 15=>new ParserAction($this->reduce, $table5),
17=>new ParserAction($this->reduce, $table5) 17=>new ParserAction($this->reduce, $table5)
); );
$tableDefinition18 = array( $tableDefinition18 = array(
5=>new ParserAction($this->reduce, $table6), 5=>new ParserAction($this->reduce, $table6),
7=>new ParserAction($this->reduce, $table6), 7=>new ParserAction($this->reduce, $table6),
8=>new ParserAction($this->reduce, $table6), 8=>new ParserAction($this->reduce, $table6),
9=>new ParserAction($this->reduce, $table6), 9=>new ParserAction($this->reduce, $table6),
11=>new ParserAction($this->reduce, $table6), 11=>new ParserAction($this->reduce, $table6),
12=>new ParserAction($this->reduce, $table6), 12=>new ParserAction($this->reduce, $table6),
15=>new ParserAction($this->reduce, $table6), 15=>new ParserAction($this->reduce, $table6),
17=>new ParserAction($this->reduce, $table6) 17=>new ParserAction($this->reduce, $table6)
); );
$tableDefinition19 = array( $tableDefinition19 = array(
5=>new ParserAction($this->reduce, $table10), 5=>new ParserAction($this->reduce, $table10),
7=>new ParserAction($this->reduce, $table10), 7=>new ParserAction($this->reduce, $table10),
8=>new ParserAction($this->reduce, $table10), 8=>new ParserAction($this->reduce, $table10),
9=>new ParserAction($this->reduce, $table10), 9=>new ParserAction($this->reduce, $table10),
11=>new ParserAction($this->reduce, $table10), 11=>new ParserAction($this->reduce, $table10),
12=>new ParserAction($this->reduce, $table10), 12=>new ParserAction($this->reduce, $table10),
15=>new ParserAction($this->reduce, $table10), 15=>new ParserAction($this->reduce, $table10),
17=>new ParserAction($this->reduce, $table10) 17=>new ParserAction($this->reduce, $table10)
); );
$tableDefinition20 = array( $tableDefinition20 = array(
5=>new ParserAction($this->reduce, $table7), 5=>new ParserAction($this->reduce, $table7),
7=>new ParserAction($this->reduce, $table7), 7=>new ParserAction($this->reduce, $table7),
8=>new ParserAction($this->reduce, $table7), 8=>new ParserAction($this->reduce, $table7),
9=>new ParserAction($this->reduce, $table7), 9=>new ParserAction($this->reduce, $table7),
11=>new ParserAction($this->reduce, $table7), 11=>new ParserAction($this->reduce, $table7),
12=>new ParserAction($this->reduce, $table7), 12=>new ParserAction($this->reduce, $table7),
15=>new ParserAction($this->reduce, $table7), 15=>new ParserAction($this->reduce, $table7),
17=>new ParserAction($this->reduce, $table7) 17=>new ParserAction($this->reduce, $table7)
); );
$table0->setActions($tableDefinition0); $table0->setActions($tableDefinition0);
$table1->setActions($tableDefinition1); $table1->setActions($tableDefinition1);
$table2->setActions($tableDefinition2); $table2->setActions($tableDefinition2);
$table3->setActions($tableDefinition3); $table3->setActions($tableDefinition3);
$table4->setActions($tableDefinition4); $table4->setActions($tableDefinition4);
$table5->setActions($tableDefinition5); $table5->setActions($tableDefinition5);
$table6->setActions($tableDefinition6); $table6->setActions($tableDefinition6);
$table7->setActions($tableDefinition7); $table7->setActions($tableDefinition7);
$table8->setActions($tableDefinition8); $table8->setActions($tableDefinition8);
$table9->setActions($tableDefinition9); $table9->setActions($tableDefinition9);
$table10->setActions($tableDefinition10); $table10->setActions($tableDefinition10);
$table11->setActions($tableDefinition11); $table11->setActions($tableDefinition11);
$table12->setActions($tableDefinition12); $table12->setActions($tableDefinition12);
$table13->setActions($tableDefinition13); $table13->setActions($tableDefinition13);
$table14->setActions($tableDefinition14); $table14->setActions($tableDefinition14);
$table15->setActions($tableDefinition15); $table15->setActions($tableDefinition15);
$table16->setActions($tableDefinition16); $table16->setActions($tableDefinition16);
$table17->setActions($tableDefinition17); $table17->setActions($tableDefinition17);
$table18->setActions($tableDefinition18); $table18->setActions($tableDefinition18);
$table19->setActions($tableDefinition19); $table19->setActions($tableDefinition19);
$table20->setActions($tableDefinition20); $table20->setActions($tableDefinition20);
$this->table = array( $this->table = array(
0=>$table0, 0=>$table0,
1=>$table1, 1=>$table1,
2=>$table2, 2=>$table2,
3=>$table3, 3=>$table3,
4=>$table4, 4=>$table4,
5=>$table5, 5=>$table5,
6=>$table6, 6=>$table6,
7=>$table7, 7=>$table7,
8=>$table8, 8=>$table8,
9=>$table9, 9=>$table9,
10=>$table10, 10=>$table10,
11=>$table11, 11=>$table11,
12=>$table12, 12=>$table12,
13=>$table13, 13=>$table13,
14=>$table14, 14=>$table14,
15=>$table15, 15=>$table15,
16=>$table16, 16=>$table16,
17=>$table17, 17=>$table17,
18=>$table18, 18=>$table18,
19=>$table19, 19=>$table19,
20=>$table20 20=>$table20
); );
$this->defaultActions = array( $this->defaultActions = array(
9=>new ParserAction($this->reduce, $table1), 9=>new ParserAction($this->reduce, $table1),
10=>new ParserAction($this->reduce, $table2) 10=>new ParserAction($this->reduce, $table2)
); );
$this->productions = array( $this->productions = array(
0=>new ParserProduction($symbol0), 0=>new ParserProduction($symbol0),
1=>new ParserProduction($symbol3,2), 1=>new ParserProduction($symbol3,2),
2=>new ParserProduction($symbol4,2), 2=>new ParserProduction($symbol4,2),
3=>new ParserProduction($symbol4,1), 3=>new ParserProduction($symbol4,1),
4=>new ParserProduction($symbol6,3), 4=>new ParserProduction($symbol6,3),
5=>new ParserProduction($symbol6,3), 5=>new ParserProduction($symbol6,3),
6=>new ParserProduction($symbol6,3), 6=>new ParserProduction($symbol6,3),
7=>new ParserProduction($symbol6,3), 7=>new ParserProduction($symbol6,3),
8=>new ParserProduction($symbol6,1), 8=>new ParserProduction($symbol6,1),
9=>new ParserProduction($symbol6,1), 9=>new ParserProduction($symbol6,1),
10=>new ParserProduction($symbol10,1), 10=>new ParserProduction($symbol10,1),
11=>new ParserProduction($symbol13,2), 11=>new ParserProduction($symbol13,2),
12=>new ParserProduction($symbol14,1), 12=>new ParserProduction($symbol14,1),
13=>new ParserProduction($symbol14,1) 13=>new ParserProduction($symbol14,1)
); );
//Setup Lexer //Setup Lexer
$this->rules = array( $this->rules = array(
0=>"/^(?:\s+)/", 0=>"/^(?:\s+)/",
1=>"/^(?:AND\b)/", 1=>"/^(?:AND\b)/",
2=>"/^(?:and\b)/", 2=>"/^(?:and\b)/",
3=>"/^(?:et\b)/", 3=>"/^(?:et\b)/",
4=>"/^(?:OR\b)/", 4=>"/^(?:OR\b)/",
5=>"/^(?:or\b)/", 5=>"/^(?:or\b)/",
6=>"/^(?:ou\b)/", 6=>"/^(?:ou\b)/",
7=>"/^(?:IN\b)/", 7=>"/^(?:IN\b)/",
8=>"/^(?:in\b)/", 8=>"/^(?:in\b)/",
9=>"/^(?:dans\b)/", 9=>"/^(?:dans\b)/",
10=>"/^(?:\()/", 10=>"/^(?:\()/",
11=>"/^(?:\))/", 11=>"/^(?:\))/",
12=>"/^(?:\*)/", 12=>"/^(?:\*)/",
13=>"/^(?:\")/", 13=>"/^(?:\")/",
14=>"/^(?:\")/", 14=>"/^(?:\")/",
15=>"/^(?:([^\"])*)/", 15=>"/^(?:([^\"])*)/",
16=>"/^(?:\S+)/", 16=>"/^(?:\S+)/",
17=>"/^(?:$)/" 17=>"/^(?:$)/"
); );
$this->conditions = array( $this->conditions = array(
"literal"=>new LexerConditions(array( 14,15), false), "literal"=>new LexerConditions(array( 14,15), false),
"INITIAL"=>new LexerConditions(array( 0,1,2,3,4,5,6,7,8,9,10,11,12,13,16,17), true) "INITIAL"=>new LexerConditions(array( 0,1,2,3,4,5,6,7,8,9,10,11,12,13,16,17), true)
); );
} }
@@ -441,72 +441,72 @@ class QueryParser
function parserPerformAction(&$thisS, &$yy, $yystate, &$s, $o) function parserPerformAction(&$thisS, &$yy, $yystate, &$s, $o)
{ {
/* this == yyval */ /* this == yyval */
switch ($yystate) { switch ($yystate) {
case 1: case 1:
return $thisS; return $thisS;
break; break;
case 2: case 2:
// $thisS = sprintf('(%s DEF_OP %s)', $s[$o-1]->text, $s[$o]->text); // $thisS = sprintf('(%s DEF_OP %s)', $s[$o-1]->text, $s[$o]->text);
$thisS = new AST\AndExpression($s[$o-1]->text, $s[$o]->text); $thisS = new AST\AndExpression($s[$o-1]->text, $s[$o]->text);
break; break;
case 4: case 4:
$thisS = new AST\AndExpression($s[$o-2]->text, $s[$o]->text); $thisS = new AST\AndExpression($s[$o-2]->text, $s[$o]->text);
break; break;
case 5: case 5:
$thisS = new AST\OrExpression($s[$o-2]->text, $s[$o]->text); $thisS = new AST\OrExpression($s[$o-2]->text, $s[$o]->text);
break; break;
case 6: case 6:
$thisS = new AST\InExpression($s[$o]->text, $s[$o-2]->text); $thisS = new AST\InExpression($s[$o]->text, $s[$o-2]->text);
break; break;
case 7: case 7:
$thisS = $s[$o-1]; $thisS = $s[$o-1];
break; break;
case 10: case 10:
$thisS = new AST\KeywordNode($s[$o]->text); $thisS = new AST\KeywordNode($s[$o]->text);
break; break;
case 11: case 11:
$thisS = new AST\PrefixNode($s[$o-1]->text); $thisS = new AST\PrefixNode($s[$o-1]->text);
break; break;
case 12: case 12:
$thisS = new AST\TextNode($s[$o]->text); $thisS = new AST\TextNode($s[$o]->text);
break; break;
case 13: case 13:
$thisS = new AST\QuotedTextNode($s[$o]->text); $thisS = new AST\QuotedTextNode($s[$o]->text);
break; break;
} }
} }
@@ -907,49 +907,49 @@ break;
function LexerPerformAction($avoidingNameCollisions, $YY_START = null) function LexerPerformAction($avoidingNameCollisions, $YY_START = null)
{ {
; ;
switch($avoidingNameCollisions) { switch($avoidingNameCollisions) {
case 0:/* skip whitespace */ case 0:/* skip whitespace */
break; break;
case 1:return 7; case 1:return 7;
break; break;
case 2:return 7; case 2:return 7;
break; break;
case 3:return 7; case 3:return 7;
break; break;
case 4:return 8; case 4:return 8;
break; break;
case 5:return 8; case 5:return 8;
break; break;
case 6:return 8; case 6:return 8;
break; break;
case 7:return 9; case 7:return 9;
break; break;
case 8:return 9; case 8:return 9;
break; break;
case 9:return 9; case 9:return 9;
break; break;
case 10:return 11; case 10:return 11;
break; break;
case 11:return 12; case 11:return 12;
break; break;
case 12:return 16; case 12:return 16;
break; break;
case 13: case 13:
$this->begin('literal'); $this->begin('literal');
break; break;
case 14: case 14:
$this->popState(); $this->popState();
break; break;
case 15:return 17; case 15:return 17;
break; break;
case 16:return 15; case 16:return 15;
break; break;
case 17:return 5; case 17:return 5;
break; break;
} }
} }
} }

View File

@@ -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);
} }

View File

@@ -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

View File

@@ -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) {