Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
lucas.parsy
jio
Commits
b1145bbb
Commit
b1145bbb
authored
Mar 15, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow for complex queries with undefined query (select all), added tests
parent
e5ac3ede
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
106 additions
and
31 deletions
+106
-31
src/jio.storage/indexstorage.js
src/jio.storage/indexstorage.js
+32
-25
src/queries/query.js
src/queries/query.js
+10
-6
test/jiotests.js
test/jiotests.js
+64
-0
No files found.
src/jio.storage/indexstorage.js
View file @
b1145bbb
...
@@ -310,8 +310,15 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -310,8 +310,15 @@ jIO.addStorageType('indexed', function (spec, my) {
priv
.
findBestIndexForQuery
=
function
(
syntax
)
{
priv
.
findBestIndexForQuery
=
function
(
syntax
)
{
var
i
,
j
,
k
,
l
,
n
,
p
,
o
,
element
,
key
,
block
,
var
i
,
j
,
k
,
l
,
n
,
p
,
o
,
element
,
key
,
block
,
search_ids
,
use_index
=
[],
select_ids
=
{},
index
,
query_param
,
search_ids
,
use_index
=
[],
select_ids
=
{},
index
,
query_param
,
// need to parse into object
current_query
,
current_query_size
;
// try to parse into object
if
(
syntax
.
query
!==
undefined
)
{
current_query
=
jIO
.
ComplexQueries
.
parse
(
syntax
.
query
);
current_query
=
jIO
.
ComplexQueries
.
parse
(
syntax
.
query
);
}
else
{
current_query
=
{};
current_query_size
=
0
;
}
// loop indices
// loop indices
for
(
i
=
0
;
i
<
priv
.
indices
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
priv
.
indices
.
length
;
i
+=
1
)
{
...
@@ -321,6 +328,7 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -321,6 +328,7 @@ jIO.addStorageType('indexed', function (spec, my) {
index
.
reference
=
priv
.
indices
[
i
];
index
.
reference
=
priv
.
indices
[
i
];
index
.
reference_size
=
index
.
reference
.
fields
.
length
;
index
.
reference_size
=
index
.
reference
.
fields
.
length
;
if
(
current_query_size
!==
0
)
{
// rebuild search_ids for iteration
// rebuild search_ids for iteration
if
(
current_query
.
query_list
===
undefined
)
{
if
(
current_query
.
query_list
===
undefined
)
{
search_ids
.
push
(
current_query
.
id
);
search_ids
.
push
(
current_query
.
id
);
...
@@ -332,11 +340,6 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -332,11 +340,6 @@ jIO.addStorageType('indexed', function (spec, my) {
}
}
}
}
}
}
// rebuild select_ids
for
(
o
=
0
;
o
<
syntax
.
filter
.
select_list
.
length
;
o
+=
1
)
{
element
=
syntax
.
filter
.
select_list
[
o
];
select_ids
[
element
]
=
true
;
}
// loop search ids and find matches in index
// loop search ids and find matches in index
for
(
k
=
0
;
k
<
search_ids
.
length
;
k
+=
1
)
{
for
(
k
=
0
;
k
<
search_ids
.
length
;
k
+=
1
)
{
...
@@ -350,6 +353,13 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -350,6 +353,13 @@ jIO.addStorageType('indexed', function (spec, my) {
}
}
}
}
}
}
}
// rebuild select_ids
for
(
o
=
0
;
o
<
syntax
.
filter
.
select_list
.
length
;
o
+=
1
)
{
element
=
syntax
.
filter
.
select_list
[
o
];
select_ids
[
element
]
=
true
;
}
// search_ids empty = all needed search fields found on index
// search_ids empty = all needed search fields found on index
if
(
search_ids
.
length
===
0
)
{
if
(
search_ids
.
length
===
0
)
{
...
@@ -915,12 +925,9 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -915,12 +925,9 @@ jIO.addStorageType('indexed', function (spec, my) {
option
,
option
,
function
(
response
)
{
function
(
response
)
{
query_syntax
=
command
.
getOption
(
'
query
'
);
query_syntax
=
command
.
getOption
(
'
query
'
);
if
(
query_syntax
!==
undefined
)
{
if
(
query_syntax
!==
undefined
)
{
// build complex query object
// build complex query object
query_object
=
priv
.
constructQueryObject
(
response
,
query_syntax
);
query_object
=
priv
.
constructQueryObject
(
response
,
query_syntax
);
if
(
query_object
.
length
===
0
)
{
if
(
query_object
.
length
===
0
)
{
that
.
addJob
(
that
.
addJob
(
"
allDocs
"
,
"
allDocs
"
,
...
...
src/queries/query.js
View file @
b1145bbb
...
@@ -165,6 +165,9 @@ Object.defineProperty(scope.ComplexQueries,"query",{
...
@@ -165,6 +165,9 @@ Object.defineProperty(scope.ComplexQueries,"query",{
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
result_list
=
[],
result_list_tmp
=
[],
j
;
result_list
=
[],
result_list_tmp
=
[],
j
;
object_list
=
object_list
||
[];
object_list
=
object_list
||
[];
if
(
query
.
query
===
undefined
)
{
result_list
=
object_list
;
}
else
{
for
(
j
=
0
;
j
<
object_list
.
length
;
++
j
)
{
for
(
j
=
0
;
j
<
object_list
.
length
;
++
j
)
{
if
(
itemMatchesQuery
(
if
(
itemMatchesQuery
(
object_list
[
j
],
scope
.
ComplexQueries
.
parse
(
query
.
query
)
object_list
[
j
],
scope
.
ComplexQueries
.
parse
(
query
.
query
)
...
@@ -172,6 +175,7 @@ Object.defineProperty(scope.ComplexQueries,"query",{
...
@@ -172,6 +175,7 @@ Object.defineProperty(scope.ComplexQueries,"query",{
result_list
.
push
(
object_list
[
j
]);
result_list
.
push
(
object_list
[
j
]);
}
}
}
}
}
if
(
query
.
filter
)
{
if
(
query
.
filter
)
{
select
(
result_list
,
query
.
filter
.
select_list
||
[]);
select
(
result_list
,
query
.
filter
.
select_list
||
[]);
sort
(
result_list
,
query
.
filter
.
sort_on
||
[]);
sort
(
result_list
,
query
.
filter
.
sort_on
||
[]);
...
...
test/jiotests.js
View file @
b1145bbb
...
@@ -1179,6 +1179,38 @@ test ("AllDocs", function(){
...
@@ -1179,6 +1179,38 @@ test ("AllDocs", function(){
},
o
.
f
);
},
o
.
f
);
o
.
tick
(
o
);
o
.
tick
(
o
);
// empty query returns all
o
.
thisShouldBeTheAnswer5
=
[
{
"
title
"
:
"
The Good, The Bad and The Ugly
"
},
{
"
title
"
:
"
The Dark Knight
"
},
{
"
title
"
:
"
Star Wars Episode V
"
},
{
"
title
"
:
"
Shawshank Redemption
"
},
{
"
title
"
:
"
Schindlers List
"
},
{
"
title
"
:
"
Pulp Fiction
"
},
{
"
title
"
:
"
One flew over the Cuckoo's Nest
"
},
{
"
title
"
:
"
Lord of the Rings - Return of the King
"
},
{
"
title
"
:
"
Lord Of the Rings - Fellowship of the Ring
"
},
{
"
title
"
:
"
Inception
"
},
{
"
title
"
:
"
Godfellas
"
},
{
"
title
"
:
"
Godfather 2
"
},
{
"
title
"
:
"
Godfather
"
},
{
"
title
"
:
"
Fight Club
"
},
{
"
title
"
:
"
12 Angry Men
"
}
];
o
.
spy
(
o
,
"
value
"
,
o
.
thisShouldBeTheAnswer5
,
"
allDocs (empty query in complex query)
"
);
o
.
jio
.
allDocs
({
"
query
"
:{
"
filter
"
:
{
"
sort_on
"
:[[
'
title
'
,
'
descending
'
]],
"
select_list
"
:[
'
title
'
]
},
"
wildcard_character
"
:
'
%
'
}
},
o
.
f
);
o
.
tick
(
o
);
o
.
jio
.
stop
();
o
.
jio
.
stop
();
});
});
...
@@ -4693,6 +4725,38 @@ test ("AllDocs Complex Queries", function () {
...
@@ -4693,6 +4725,38 @@ test ("AllDocs Complex Queries", function () {
},
o
.
f
);
},
o
.
f
);
o
.
tick
(
o
);
o
.
tick
(
o
);
// empty query returns all
o
.
thisShouldBeTheAnswer6
=
[
{
"
title
"
:
"
The Good, The Bad and The Ugly
"
},
{
"
title
"
:
"
The Dark Knight
"
},
{
"
title
"
:
"
Star Wars Episode V
"
},
{
"
title
"
:
"
Shawshank Redemption
"
},
{
"
title
"
:
"
Schindlers List
"
},
{
"
title
"
:
"
Pulp Fiction
"
},
{
"
title
"
:
"
One flew over the Cuckoo's Nest
"
},
{
"
title
"
:
"
Lord of the Rings - Return of the King
"
},
{
"
title
"
:
"
Lord Of the Rings - Fellowship of the Ring
"
},
{
"
title
"
:
"
Inception
"
},
{
"
title
"
:
"
Godfellas
"
},
{
"
title
"
:
"
Godfather 2
"
},
{
"
title
"
:
"
Godfather
"
},
{
"
title
"
:
"
Fight Club
"
},
{
"
title
"
:
"
12 Angry Men
"
}
];
o
.
spy
(
o
,
"
value
"
,
o
.
thisShouldBeTheAnswer6
,
"
allDocs (empty query in complex query)
"
);
o
.
jio
.
allDocs
({
"
query
"
:{
"
filter
"
:
{
"
sort_on
"
:[[
'
title
'
,
'
descending
'
]],
"
select_list
"
:[
'
title
'
]
},
"
wildcard_character
"
:
'
%
'
}
},
o
.
f
);
o
.
tick
(
o
);
o
.
jio
.
stop
();
o
.
jio
.
stop
();
});
});
/*
/*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment