Commit d9c640aa authored by Oliver Giles's avatar Oliver Giles Committed by Vladislav Vaintroub

SphinxSE: add support for json filtering

The filter command did not accept characters . [ ] which are valid
in an attribute name for a sphinx query with json filtering.

+ test case added
parent 3a24f1cf
...@@ -1411,6 +1411,14 @@ static bool myismagic ( char c ) ...@@ -1411,6 +1411,14 @@ static bool myismagic ( char c )
return c=='@'; return c=='@';
} }
static bool myisjson ( char c )
{
return
c=='.' ||
c=='[' ||
c==']';
}
bool CSphSEQuery::ParseField ( char * sField ) bool CSphSEQuery::ParseField ( char * sField )
{ {
...@@ -1622,7 +1630,7 @@ bool CSphSEQuery::ParseField ( char * sField ) ...@@ -1622,7 +1630,7 @@ bool CSphSEQuery::ParseField ( char * sField )
break; break;
tFilter.m_sAttrName = sValue; tFilter.m_sAttrName = sValue;
while ( (*sValue) && ( myisattr(*sValue) || myismagic(*sValue) ) ) while ( (*sValue) && ( myisattr(*sValue) || myismagic(*sValue) || myisjson(*sValue) ) )
sValue++; sValue++;
if ( !*sValue ) if ( !*sValue )
break; break;
......
...@@ -4,17 +4,20 @@ id w q ...@@ -4,17 +4,20 @@ id w q
1 2 test 1 2 test
2 2 test 2 2 test
4 1 test 4 1 test
5 1 test
drop table ts; drop table ts;
create table ts ( id bigint unsigned not null, w int not null, q varchar(255) not null, index(q) ) engine=sphinx connection="sphinx://127.0.0.1:SPHINXSEARCH_PORT/*"; create table ts ( id bigint unsigned not null, w int not null, q varchar(255) not null, index(q) ) engine=sphinx connection="sphinx://127.0.0.1:SPHINXSEARCH_PORT/*";
select * from ts where q='test;filter=gid,1;mode=extended'; select * from ts where q='test;filter=gid,1;mode=extended';
id w q id w q
1 2421 test;filter=gid,1;mode=extended 1 2379 test;filter=gid,1;mode=extended
2 2421 test;filter=gid,1;mode=extended 2 2379 test;filter=gid,1;mode=extended
5 1412 test;filter=gid,1;mode=extended
select * from ts where q='test|one;mode=extended'; select * from ts where q='test|one;mode=extended';
id w q id w q
1 3595 test|one;mode=extended 1 3579 test|one;mode=extended
2 2460 test|one;mode=extended 2 2439 test|one;mode=extended
4 1471 test|one;mode=extended 4 1456 test|one;mode=extended
5 1456 test|one;mode=extended
select * from ts where q='test;offset=1;limit=1'; select * from ts where q='test;offset=1;limit=1';
id w q id w q
2 2 test;offset=1;limit=1 2 2 test;offset=1;limit=1
...@@ -32,10 +35,11 @@ id w q gid _sph_count ...@@ -32,10 +35,11 @@ id w q gid _sph_count
2 1 1 0 2 1 1 0
3 1 2 0 3 1 2 0
4 1 2 0 4 1 2 0
5 1 1 0
select * from ts where q=';groupby=attr:gid'; select * from ts where q=';groupby=attr:gid';
id w q gid _sph_count id w q gid _sph_count
3 1 ;groupby=attr:gid 2 2 3 1 ;groupby=attr:gid 2 2
1 1 ;groupby=attr:gid 1 2 1 1 ;groupby=attr:gid 1 3
explain select * from ts where q=';groupby=attr:gid'; explain select * from ts where q=';groupby=attr:gid';
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE ts ref q q 257 const 3 Using where with pushed condition 1 SIMPLE ts ref q q 257 const 3 Using where with pushed condition
...@@ -54,3 +58,20 @@ show status like "sphinx_word%"; ...@@ -54,3 +58,20 @@ show status like "sphinx_word%";
Variable_name Value Variable_name Value
Sphinx_word_count 0 Sphinx_word_count 0
Sphinx_words Sphinx_words
create table ts ( id bigint unsigned not null, w int not null, q varchar(255) not null, index(q) ) engine=sphinx connection="sphinx://127.0.0.1:SPHINXSEARCH_PORT/*";
select * from ts where q=';filter=meta.foo_count,100';
id w q
1 1 ;filter=meta.foo_count,100
select * from ts where q='test;filter=meta.sub.int,7';
id w q
5 1 test;filter=meta.sub.int,7
select * from ts where q=';filter=meta.sub.list[0],4';
id w q
select * from ts where q=';filter=meta.sub.list[1],4';
id w q
5 1 ;filter=meta.sub.list[1],4
select * from ts where q='test;range=meta.foo_count,100,500';
id w q
1 2 test;range=meta.foo_count,100,500
5 1 test;range=meta.foo_count,100,500
drop table ts;
...@@ -32,3 +32,12 @@ drop table ts; ...@@ -32,3 +32,12 @@ drop table ts;
show status like "sphinx_total%"; show status like "sphinx_total%";
show status like "sphinx_word%"; show status like "sphinx_word%";
--replace_result $SPHINXSEARCH_PORT SPHINXSEARCH_PORT
eval create table ts ( id bigint unsigned not null, w int not null, q varchar(255) not null, index(q) ) engine=sphinx connection="sphinx://127.0.0.1:$SPHINXSEARCH_PORT/*";
select * from ts where q=';filter=meta.foo_count,100';
select * from ts where q='test;filter=meta.sub.int,7';
select * from ts where q=';filter=meta.sub.list[0],4';
select * from ts where q=';filter=meta.sub.list[1],4';
select * from ts where q='test;range=meta.foo_count,100,500';
drop table ts;
...@@ -5,12 +5,14 @@ ...@@ -5,12 +5,14 @@
<sphinx:field name="title"/> <sphinx:field name="title"/>
<sphinx:field name="content"/> <sphinx:field name="content"/>
<sphinx:attr name="gid" type="int"/> <sphinx:attr name="gid" type="int"/>
<sphinx:attr name="meta" type="json"/>
</sphinx:schema> </sphinx:schema>
<sphinx:document id="1"> <sphinx:document id="1">
<title>test one</title> <title>test one</title>
<content>this is my test document number one. also checking search within phrases.</content> <content>this is my test document number one. also checking search within phrases.</content>
<gid>1</gid> <gid>1</gid>
<meta>{ "foo_count": 100 }</meta>
</sphinx:document> </sphinx:document>
<sphinx:document id="2"> <sphinx:document id="2">
...@@ -31,5 +33,12 @@ ...@@ -31,5 +33,12 @@
<gid>2</gid> <gid>2</gid>
</sphinx:document> </sphinx:document>
<sphinx:document id="5">
<title>doc number five</title>
<content>this is to test json filtering</content>
<gid>1</gid>
<meta>{ "foo_count": 200, "sub": { "list": [ 3, 4 ], "int": 7 } }</meta>
</sphinx:document>
</sphinx:docset> </sphinx:docset>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment