Skip to content
Permalink
Browse files

fixed bool queries vs json select list

  • Loading branch information
glookka committed Nov 13, 2019
1 parent 69a985f commit cf10d7d3589f77adfaefbe52a51777bc9c67cf99
Showing with 88 additions and 11 deletions.
  1. +8 −9 src/sphinxjsonquery.cpp
  2. +29 −1 test/test_330/model.bin
  3. +51 −1 test/test_330/test.xml
@@ -1066,33 +1066,32 @@ static bool ConstructBoolFilters ( const JsonObj_c & tBool, CSphQuery & tQuery,

if ( dMustNot.GetLength() )
{
int iFilter = dMust.GetLength();
dMust.Resize ( dMust.GetLength()+dMustNot.GetLength() );
for ( auto & i : dMustNot )
{
i.m_bExclude = true;
dMust[iFilter++] = i;
dMust.Add(i);
}

int iQueryItem = dMustQI.GetLength();
dMustQI.Resize ( dMustQI.GetLength()+dMustNotQI.GetLength() );
for ( auto & i : dMustNotQI )
dMustQI[iQueryItem++] = i;
dMustQI.Add(i);
}

if ( dMust.GetLength() )
{
AddToSelectList ( tQuery, dMustQI );
tQuery.m_dFilters.SwapData ( dMust );
tQuery.m_dItems.SwapData ( dMustQI );
for ( const auto & i : dMustQI )
tQuery.m_dItems.Add(i);

return true;
}

if ( dShould.GetLength() )
{
AddToSelectList ( tQuery, dShouldQI );
tQuery.m_dFilters.SwapData ( dShould );
tQuery.m_dItems.SwapData ( dShouldQI );
for ( const auto & i : dShouldQI )
tQuery.m_dItems.Add(i);

// need a filter tree
FilterTreeItem_t & tTreeItem = tQuery.m_dFilterTree.Add();
@@ -1877,7 +1876,7 @@ CSphString sphEncodeResultJson ( const AggrResult_t & tRes, const CSphQuery & tQ

tOut.StartBlock ( ",", R"("hits":[)", "]" );

const CSphColumnInfo * pId = tSchema.GetAttr ( sphGetDocidName() );
const CSphColumnInfo * pId = tSchema.GetAttr ( sphGetDocidName() );

for ( int iMatch=tRes.m_iOffset; iMatch<tRes.m_iOffset+tRes.m_iCount; ++iMatch )
{
@@ -1 +1,29 @@
a:1:{i:0;a:4:{i:0;a:6:{s:13:"http_endpoint";s:11:"json/search";s:11:"http_method";s:4:"POST";s:12:"http_request";s:81:"{ "index": "test", "query": { "match": { "title": "fill" } }, "_source": "*id*" }";s:4:"rows";s:344:"{"timed_out":false,"hits":{"total":3,"hits":[{"_id":"10","_score":1319,"_source":{"gid101":11,"gid102":12,"fid105":13,"bid201":14,"sid202":15}},{"_id":"11","_score":1319,"_source":{"gid101":21,"gid102":22,"fid105":23,"bid201":24,"sid202":25}},{"_id":"12","_score":1319,"_source":{"gid101":31,"gid102":32,"fid105":33,"bid201":34,"sid202":35}}]}}";s:9:"http_code";i:200;s:4:"http";i:1;}i:1;a:6:{s:13:"http_endpoint";s:11:"json/search";s:11:"http_method";s:4:"POST";s:12:"http_request";s:90:"{ "index": "test", "query": { "match": { "title": "fill" } }, "_source": ["gi*", "*20*"] }";s:4:"rows";s:308:"{"timed_out":false,"hits":{"total":3,"hits":[{"_id":"10","_score":1319,"_source":{"gid101":11,"gid102":12,"bid201":14,"sid202":15}},{"_id":"11","_score":1319,"_source":{"gid101":21,"gid102":22,"bid201":24,"sid202":25}},{"_id":"12","_score":1319,"_source":{"gid101":31,"gid102":32,"bid201":34,"sid202":35}}]}}";s:9:"http_code";i:200;s:4:"http";i:1;}i:2;a:6:{s:13:"http_endpoint";s:11:"json/search";s:11:"http_method";s:4:"POST";s:12:"http_request";s:110:"{ "index": "test", "query": { "match": { "title": "fill" } }, "_source": { "includes":["*"], "excludes":[] } }";s:4:"rows";s:167:"{"timed_out":false,"hits":{"total":3,"hits":[{"_id":"10","_score":1319,"_source":{}},{"_id":"11","_score":1319,"_source":{}},{"_id":"12","_score":1319,"_source":{}}]}}";s:9:"http_code";i:200;s:4:"http";i:1;}i:3;a:6:{s:13:"http_endpoint";s:11:"json/search";s:11:"http_method";s:4:"POST";s:12:"http_request";s:106:"{ "index": "test", "query": { "match": { "title": "fill" } }, "_source": { "excludes":["*02", "*id1*"] } }";s:4:"rows";s:200:"{"timed_out":false,"hits":{"total":3,"hits":[{"_id":"10","_score":1319,"_source":{"bid201":14}},{"_id":"11","_score":1319,"_source":{"bid201":24}},{"_id":"12","_score":1319,"_source":{"bid201":34}}]}}";s:9:"http_code";i:200;s:4:"http";i:1;}}}
a:1:{i:0;a:5:{i:0;a:6:{s:13:"http_endpoint";s:11:"json/search";s:11:"http_method";s:4:"POST";s:12:"http_request";s:81:"{ "index": "test", "query": { "match": { "title": "fill" } }, "_source": "*id*" }";s:4:"rows";s:344:"{"timed_out":false,"hits":{"total":3,"hits":[{"_id":"10","_score":1319,"_source":{"gid101":11,"gid102":12,"fid105":13,"bid201":14,"sid202":15}},{"_id":"11","_score":1319,"_source":{"gid101":21,"gid102":22,"fid105":23,"bid201":24,"sid202":25}},{"_id":"12","_score":1319,"_source":{"gid101":31,"gid102":32,"fid105":33,"bid201":34,"sid202":35}}]}}";s:9:"http_code";i:200;s:4:"http";i:1;}i:1;a:6:{s:13:"http_endpoint";s:11:"json/search";s:11:"http_method";s:4:"POST";s:12:"http_request";s:90:"{ "index": "test", "query": { "match": { "title": "fill" } }, "_source": ["gi*", "*20*"] }";s:4:"rows";s:308:"{"timed_out":false,"hits":{"total":3,"hits":[{"_id":"10","_score":1319,"_source":{"gid101":11,"gid102":12,"bid201":14,"sid202":15}},{"_id":"11","_score":1319,"_source":{"gid101":21,"gid102":22,"bid201":24,"sid202":25}},{"_id":"12","_score":1319,"_source":{"gid101":31,"gid102":32,"bid201":34,"sid202":35}}]}}";s:9:"http_code";i:200;s:4:"http";i:1;}i:2;a:6:{s:13:"http_endpoint";s:11:"json/search";s:11:"http_method";s:4:"POST";s:12:"http_request";s:110:"{ "index": "test", "query": { "match": { "title": "fill" } }, "_source": { "includes":["*"], "excludes":[] } }";s:4:"rows";s:167:"{"timed_out":false,"hits":{"total":3,"hits":[{"_id":"10","_score":1319,"_source":{}},{"_id":"11","_score":1319,"_source":{}},{"_id":"12","_score":1319,"_source":{}}]}}";s:9:"http_code";i:200;s:4:"http";i:1;}i:3;a:6:{s:13:"http_endpoint";s:11:"json/search";s:11:"http_method";s:4:"POST";s:12:"http_request";s:106:"{ "index": "test", "query": { "match": { "title": "fill" } }, "_source": { "excludes":["*02", "*id1*"] } }";s:4:"rows";s:200:"{"timed_out":false,"hits":{"total":3,"hits":[{"_id":"10","_score":1319,"_source":{"bid201":14}},{"_id":"11","_score":1319,"_source":{"bid201":24}},{"_id":"12","_score":1319,"_source":{"bid201":34}}]}}";s:9:"http_code";i:200;s:4:"http";i:1;}i:4;a:6:{s:13:"http_endpoint";s:11:"json/search";s:11:"http_method";s:4:"POST";s:12:"http_request";s:510:"
{
"query":{
"bool":{
"must":[
{
"match":{
"*":"fill"
}
}
],
"should":[
{
"equals":{
"gid101":1
}
},
{
"equals":{
"gid101":11
}
}
]
}
},
"index":"test,test2",
"limit":5
}
";s:4:"rows";s:239:"{"timed_out":false,"hits":{"total":2,"hits":[{"_id":"1","_score":1500,"_source":{"gid101":1,"gid102":2,"fid105":3,"bid201":4,"sid202":5}},{"_id":"10","_score":1319,"_source":{"gid101":11,"gid102":12,"fid105":13,"bid201":14,"sid202":15}}]}}";s:9:"http_code";i:200;s:4:"http";i:1;}}}
@@ -18,7 +18,19 @@ source src_test
{
type = mysql
<sql_settings/>
sql_query = SELECT id, gid101, gid102, fid105, bid201, sid202, title FROM test_table
sql_query = SELECT id, gid101, gid102, fid105, bid201, sid202, title FROM test_table where id&gt;=10
sql_attr_uint = gid101
sql_attr_uint = gid102
sql_attr_uint = fid105
sql_attr_uint = bid201
sql_attr_uint = sid202
}

source src_test2
{
type = mysql
<sql_settings/>
sql_query = SELECT id, gid101, gid102, fid105, bid201, sid202, title FROM test_table where id&lt;10
sql_attr_uint = gid101
sql_attr_uint = gid102
sql_attr_uint = fid105
@@ -33,6 +45,13 @@ index test
path = <data_path/>/test
}

index test2
{
source = src_test2
path = <data_path/>/test2
}


</config>

<db_drop>drop table if exists test_table</db_drop>
@@ -52,6 +71,7 @@ create table test_table

<db_insert>
insert into test_table values
(1, '1th fill', 1, 2, 3, 4, 5 ),
(10, '10th fill', 11, 12, 13, 14, 15 ),
(11, '11th fill', 21, 22, 23, 24, 25 ),
(12, '12th fill', 31, 32, 33, 34, 35 )
@@ -64,6 +84,36 @@ insert into test_table values
<query endpoint="json/search">{ "index": "test", "query": { "match": { "title": "fill" } }, "_source": { "includes":["*"], "excludes":[] } }</query>
<query endpoint="json/search">{ "index": "test", "query": { "match": { "title": "fill" } }, "_source": { "excludes":["*02", "*id1*"] } }</query>

<query endpoint="json/search">
{
"query":{
"bool":{
"must":[
{
"match":{
"*":"fill"
}
}
],
"should":[
{
"equals":{
"gid101":1
}
},
{
"equals":{
"gid101":11
}
}
]
}
},
"index":"test,test2",
"limit":5
}
</query>

</httpqueries>

</test>

0 comments on commit cf10d7d

Please sign in to comment.
You can’t perform that action at this time.