Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Yaxel Perez
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
Hide 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) {
priv
.
findBestIndexForQuery
=
function
(
syntax
)
{
var
i
,
j
,
k
,
l
,
n
,
p
,
o
,
element
,
key
,
block
,
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
);
}
else
{
current_query
=
{};
current_query_size
=
0
;
}
// loop indices
for
(
i
=
0
;
i
<
priv
.
indices
.
length
;
i
+=
1
)
{
...
...
@@ -321,36 +328,39 @@ jIO.addStorageType('indexed', function (spec, my) {
index
.
reference
=
priv
.
indices
[
i
];
index
.
reference_size
=
index
.
reference
.
fields
.
length
;
// rebuild search_ids for iteration
if
(
current_query
.
query_list
===
undefined
)
{
search_ids
.
push
(
current_query
.
id
);
}
else
{
for
(
j
=
0
;
j
<
current_query
.
query_list
.
length
;
j
+=
1
)
{
if
(
priv
.
getPositionInArray
(
current_query
.
query_list
[
j
].
id
,
search_ids
)
===
null
)
{
search_ids
.
push
(
current_query
.
query_list
[
j
].
id
);
if
(
current_query_size
!==
0
)
{
// rebuild search_ids for iteration
if
(
current_query
.
query_list
===
undefined
)
{
search_ids
.
push
(
current_query
.
id
);
}
else
{
for
(
j
=
0
;
j
<
current_query
.
query_list
.
length
;
j
+=
1
)
{
if
(
priv
.
getPositionInArray
(
current_query
.
query_list
[
j
].
id
,
search_ids
)
===
null
)
{
search_ids
.
push
(
current_query
.
query_list
[
j
].
id
);
}
}
}
// loop search ids and find matches in index
for
(
k
=
0
;
k
<
search_ids
.
length
;
k
+=
1
)
{
query_param
=
search_ids
[
0
];
for
(
l
=
0
;
l
<
index
.
reference_size
;
l
+=
1
)
{
if
(
query_param
===
index
.
reference
.
fields
[
l
])
{
search_ids
.
splice
(
priv
.
getPositionInArray
(
query_param
,
search_ids
),
1
);
}
}
}
}
// 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
for
(
k
=
0
;
k
<
search_ids
.
length
;
k
+=
1
)
{
query_param
=
search_ids
[
0
];
for
(
l
=
0
;
l
<
index
.
reference_size
;
l
+=
1
)
{
if
(
query_param
===
index
.
reference
.
fields
[
l
])
{
search_ids
.
splice
(
priv
.
getPositionInArray
(
query_param
,
search_ids
),
1
);
}
}
}
// search_ids empty = all needed search fields found on index
if
(
search_ids
.
length
===
0
)
{
p
=
priv
.
getObjectSize
(
select_ids
);
...
...
@@ -915,12 +925,9 @@ jIO.addStorageType('indexed', function (spec, my) {
option
,
function
(
response
)
{
query_syntax
=
command
.
getOption
(
'
query
'
);
if
(
query_syntax
!==
undefined
)
{
// build complex query object
query_object
=
priv
.
constructQueryObject
(
response
,
query_syntax
);
if
(
query_object
.
length
===
0
)
{
that
.
addJob
(
"
allDocs
"
,
...
...
src/queries/query.js
View file @
b1145bbb
...
...
@@ -165,12 +165,16 @@ Object.defineProperty(scope.ComplexQueries,"query",{
////////////////////////////////////////////////////////////
result_list
=
[],
result_list_tmp
=
[],
j
;
object_list
=
object_list
||
[];
for
(
j
=
0
;
j
<
object_list
.
length
;
++
j
)
{
if
(
itemMatchesQuery
(
object_list
[
j
],
scope
.
ComplexQueries
.
parse
(
query
.
query
)
))
{
result_list
.
push
(
object_list
[
j
]);
}
if
(
query
.
query
===
undefined
)
{
result_list
=
object_list
;
}
else
{
for
(
j
=
0
;
j
<
object_list
.
length
;
++
j
)
{
if
(
itemMatchesQuery
(
object_list
[
j
],
scope
.
ComplexQueries
.
parse
(
query
.
query
)
))
{
result_list
.
push
(
object_list
[
j
]);
}
}
}
if
(
query
.
filter
)
{
select
(
result_list
,
query
.
filter
.
select_list
||
[]);
...
...
test/jiotests.js
View file @
b1145bbb
...
...
@@ -1179,6 +1179,38 @@ test ("AllDocs", function(){
},
o
.
f
);
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
();
});
...
...
@@ -4693,6 +4725,38 @@ test ("AllDocs Complex Queries", function () {
},
o
.
f
);
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
();
});
/*
...
...
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