Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio-main
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
Hardik Juneja
jio-main
Commits
555c5b3d
Commit
555c5b3d
authored
Feb 05, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
indexStorage: fixed ALLDOCS complex queries, added QUnit tests
parent
d2c42f76
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
365 additions
and
79 deletions
+365
-79
src/jio.storage/indexstorage.js
src/jio.storage/indexstorage.js
+181
-60
test/jiotests.js
test/jiotests.js
+184
-19
No files found.
src/jio.storage/indexstorage.js
View file @
555c5b3d
This diff is collapsed.
Click to expand it.
test/jiotests.js
View file @
555c5b3d
...
@@ -244,7 +244,15 @@ generateTools = function (sinon) {
...
@@ -244,7 +244,15 @@ generateTools = function (sinon) {
o
.
server
.
respondWith
(
method
,
url
,
o
.
server
.
respondWith
(
method
,
url
,
[
status
,
{
"
Content-Type
"
:
'
application/xml
'
},
response
]
[
status
,
{
"
Content-Type
"
:
'
application/xml
'
},
response
]
);
);
}
};
o
.
sortArrayById
=
function
(
field
,
reverse
,
primer
){
var
key
=
function
(
x
)
{
return
primer
?
primer
(
x
[
field
])
:
x
[
field
]};
return
function
(
a
,
b
)
{
var
A
=
key
(
a
),
B
=
key
(
b
);
return
(
(
A
<
B
)
?
-
1
:
((
A
>
B
)
?
1
:
0
)
)
*
[
-
1
,
1
][
+!!
reverse
];
}
};
return
o
;
return
o
;
},
},
...
@@ -1097,7 +1105,7 @@ test ("AllDocs", function(){
...
@@ -1097,7 +1105,7 @@ test ("AllDocs", function(){
"
Peter Jackson
"
,
"
David Fincher
"
,
"
Irvin Kershner
"
,
"
Peter Jackson
"
,
"
Peter Jackson
"
,
"
David Fincher
"
,
"
Irvin Kershner
"
,
"
Peter Jackson
"
,
"
Milos Forman
"
,
"
Christopher Nolan
"
,
"
Martin Scorsese
"
"
Milos Forman
"
,
"
Christopher Nolan
"
,
"
Martin Scorsese
"
]
]
// set documents
for
(
i
=
0
;
i
<
m
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
m
;
i
+=
1
)
{
o
.
fakeDoc
=
{};
o
.
fakeDoc
=
{};
o
.
fakeDoc
.
_id
=
"
doc_
"
+
i
;
o
.
fakeDoc
.
_id
=
"
doc_
"
+
i
;
...
@@ -2790,6 +2798,10 @@ test ("Post", function () {
...
@@ -2790,6 +2798,10 @@ test ("Post", function () {
{
"
name
"
:
"
indexA
"
,
"
fields
"
:[
"
findMeA
"
]},
{
"
name
"
:
"
indexA
"
,
"
fields
"
:[
"
findMeA
"
]},
{
"
name
"
:
"
indexAB
"
,
"
fields
"
:[
"
findMeA
"
,
"
findMeB
"
]}
{
"
name
"
:
"
indexAB
"
,
"
fields
"
:[
"
findMeA
"
,
"
findMeB
"
]}
],
],
"
field_types
"
:
{
"
findMeA
"
:
"
string
"
,
"
findMeB
"
:
"
string
"
},
"
sub_storage
"
:
{
"
sub_storage
"
:
{
"
type
"
:
"
local
"
,
"
type
"
:
"
local
"
,
"
username
"
:
"
ipost
"
,
"
username
"
:
"
ipost
"
,
...
@@ -2863,6 +2875,10 @@ test ("Put", function(){
...
@@ -2863,6 +2875,10 @@ test ("Put", function(){
{
"
name
"
:
"
indexA
"
,
"
fields
"
:[
"
author
"
]},
{
"
name
"
:
"
indexA
"
,
"
fields
"
:[
"
author
"
]},
{
"
name
"
:
"
indexAB
"
,
"
fields
"
:[
"
author
"
,
"
year
"
]}
{
"
name
"
:
"
indexAB
"
,
"
fields
"
:[
"
author
"
,
"
year
"
]}
],
],
"
field_types
"
:
{
"
author
"
:
"
string
"
,
"
year
"
:
"
number
"
},
"
sub_storage
"
:
{
"
sub_storage
"
:
{
"
type
"
:
"
local
"
,
"
type
"
:
"
local
"
,
"
username
"
:
"
iput
"
,
"
username
"
:
"
iput
"
,
...
@@ -3035,6 +3051,10 @@ test ("PutAttachment", function(){
...
@@ -3035,6 +3051,10 @@ test ("PutAttachment", function(){
{
"
name
"
:
"
indexA
"
,
"
fields
"
:[
"
author
"
]},
{
"
name
"
:
"
indexA
"
,
"
fields
"
:[
"
author
"
]},
{
"
name
"
:
"
indexAB
"
,
"
fields
"
:[
"
author
"
,
"
year
"
]}
{
"
name
"
:
"
indexAB
"
,
"
fields
"
:[
"
author
"
,
"
year
"
]}
],
],
"
field_types
"
:
{
"
author
"
:
"
string
"
,
"
year
"
:
"
number
"
},
"
sub_storage
"
:
{
"
sub_storage
"
:
{
"
type
"
:
"
local
"
,
"
type
"
:
"
local
"
,
"
username
"
:
"
iputatt
"
,
"
username
"
:
"
iputatt
"
,
...
@@ -3142,6 +3162,10 @@ test ("Get", function(){
...
@@ -3142,6 +3162,10 @@ test ("Get", function(){
{
"
name
"
:
"
indexA
"
,
"
fields
"
:[
"
author
"
]},
{
"
name
"
:
"
indexA
"
,
"
fields
"
:[
"
author
"
]},
{
"
name
"
:
"
indexAB
"
,
"
fields
"
:[
"
author
"
,
"
year
"
]}
{
"
name
"
:
"
indexAB
"
,
"
fields
"
:[
"
author
"
,
"
year
"
]}
],
],
"
field_types
"
:
{
"
author
"
:
"
string
"
,
"
year
"
:
"
number
"
},
"
sub_storage
"
:
{
"
sub_storage
"
:
{
"
type
"
:
"
local
"
,
"
type
"
:
"
local
"
,
"
username
"
:
"
iget
"
,
"
username
"
:
"
iget
"
,
...
@@ -3208,6 +3232,10 @@ test ("Remove", function(){
...
@@ -3208,6 +3232,10 @@ test ("Remove", function(){
{
"
name
"
:
"
indexA
"
,
"
fields
"
:[
"
author
"
]},
{
"
name
"
:
"
indexA
"
,
"
fields
"
:[
"
author
"
]},
{
"
name
"
:
"
indexAB
"
,
"
fields
"
:[
"
author
"
,
"
year
"
]}
{
"
name
"
:
"
indexAB
"
,
"
fields
"
:[
"
author
"
,
"
year
"
]}
],
],
"
field_types
"
:
{
"
author
"
:
"
string
"
,
"
year
"
:
"
number
"
},
"
sub_storage
"
:
{
"
sub_storage
"
:
{
"
type
"
:
"
local
"
,
"
type
"
:
"
local
"
,
"
username
"
:
"
irem
"
,
"
username
"
:
"
irem
"
,
...
@@ -3372,6 +3400,10 @@ test ("AllDocs", function () {
...
@@ -3372,6 +3400,10 @@ test ("AllDocs", function () {
{
"
name
"
:
"
indexA
"
,
"
fields
"
:[
"
author
"
]},
{
"
name
"
:
"
indexA
"
,
"
fields
"
:[
"
author
"
]},
{
"
name
"
:
"
indexAB
"
,
"
fields
"
:[
"
author
"
,
"
year
"
]}
{
"
name
"
:
"
indexAB
"
,
"
fields
"
:[
"
author
"
,
"
year
"
]}
],
],
"
field_types
"
:
{
"
author
"
:
"
string
"
,
"
year
"
:
"
number
"
},
"
sub_storage
"
:
{
"
sub_storage
"
:
{
"
type
"
:
"
local
"
,
"
type
"
:
"
local
"
,
"
username
"
:
"
iall
"
,
"
username
"
:
"
iall
"
,
...
@@ -3461,25 +3493,158 @@ test ("AllDocs", function () {
...
@@ -3461,25 +3493,158 @@ test ("AllDocs", function () {
o
.
spy
(
o
,
"
value
"
,
o
.
thisShouldBeTheAnswer2
,
"
allDocs (include_docs)
"
);
o
.
spy
(
o
,
"
value
"
,
o
.
thisShouldBeTheAnswer2
,
"
allDocs (include_docs)
"
);
o
.
jio
.
allDocs
({
"
include_docs
"
:
true
},
o
.
f
);
o
.
jio
.
allDocs
({
"
include_docs
"
:
true
},
o
.
f
);
o
.
tick
(
o
);
o
.
tick
(
o
);
/*
// complex queries
o
.
jio
.
stop
();
o.thisShouldBeTheAnswer3 = {"nothing here":"yet"}
});
o.spy(o, "value", o.thisShouldBeTheAnswer3,
"allDocs (complex queries year >= 1985)");
test
(
"
AllDocs Complex Queries
"
,
function
()
{
o.jio.allDocs({
"query":{
var
o
=
generateTools
(
this
),
i
,
m
=
15
;
"query":jIO.ComplexQueries.parse('(year: >= "1985" AND author:"D%")'),
"filter": {
o
.
jio
=
JIO
.
newJio
({
"limit":[0,2],
"
type
"
:
"
indexed
"
,
"sort_on":[['key','descending']],
"
indices
"
:
[
"select_list":['author','year']
{
"
name
"
:
"
indexA
"
,
"
fields
"
:[
"
director
"
]},
{
"
name
"
:
"
indexAB
"
,
"
fields
"
:[
"
title
"
,
"
year
"
]}
//,
//{"name":"indexABC", "fields":["title","year","director"]}
],
"
field_types
"
:
{
"
director
"
:
"
string
"
,
"
title
"
:
"
string
"
,
"
year
"
:
"
number
"
},
},
"wildcard_character":'%'
"
sub_storage
"
:
{
"
type
"
:
"
local
"
,
"
username
"
:
"
icomplex
"
,
"
application_name
"
:
"
acomplex
"
}
});
o
.
localpath
=
"
jio/localstorage/icomplex/acomplex
"
;
// sample data
o
.
titles
=
[
"
Shawshank Redemption
"
,
"
Godfather
"
,
"
Godfather 2
"
,
"
Pulp Fiction
"
,
"
The Good, The Bad and The Ugly
"
,
"
12 Angry Men
"
,
"
The Dark Knight
"
,
"
Schindlers List
"
,
"
Lord of the Rings - Return of the King
"
,
"
Fight Club
"
,
"
Star Wars Episode V
"
,
"
Lord Of the Rings - Fellowship of the Ring
"
,
"
One flew over the Cuckoo's Nest
"
,
"
Inception
"
,
"
Godfellas
"
];
o
.
years
=
[
1994
,
1972
,
1974
,
1994
,
1966
,
1957
,
2008
,
1993
,
2003
,
1999
,
1980
,
2001
,
1975
,
2010
,
1990
];
o
.
director
=
[
"
Frank Darabont
"
,
"
Francis Ford Coppola
"
,
"
Francis Ford Coppola
"
,
"
Quentin Tarantino
"
,
"
Sergio Leone
"
,
"
Sidney Lumet
"
,
"
Christopher Nolan
"
,
"
Steven Spielberg
"
,
"
Peter Jackson
"
,
"
David Fincher
"
,
"
Irvin Kershner
"
,
"
Peter Jackson
"
,
"
Milos Forman
"
,
"
Christopher Nolan
"
,
"
Martin Scorsese
"
]
for
(
i
=
0
;
i
<
m
;
i
+=
1
)
{
o
.
fakeDoc
=
{};
o
.
fakeDoc
.
_id
=
""
+
i
;
o
.
fakeDoc
.
title
=
o
.
titles
[
i
];
o
.
fakeDoc
.
year
=
o
.
years
[
i
];
o
.
fakeDoc
.
director
=
o
.
director
[
i
];
o
.
jio
.
put
(
o
.
fakeDoc
);
o
.
clock
.
tick
(
1000
);
}
}
}, o.f);
o.tick(o);
// response
*/
o
.
allDocsResponse
=
{};
o
.
jio
.
stop
();
o
.
allDocsResponse
.
rows
=
[];
o
.
allDocsResponse
.
total_rows
=
15
;
for
(
i
=
0
;
i
<
m
;
i
+=
1
)
{
o
.
allDocsResponse
.
rows
.
push
({
"
id
"
:
""
+
i
,
"
key
"
:
""
+
i
,
"
value
"
:
{}
});
};
// alldocs
o
.
jio
.
allDocs
(
function
(
e
,
r
)
{
var
x
=
r
.
rows
.
sort
(
o
.
sortArrayById
(
'
id
'
,
true
,
parseInt
));
deepEqual
(
{
"
total_rows
"
:
r
.
total_rows
,
"
rows
"
:
x
},
o
.
allDocsResponse
,
"
AllDocs response generated from index
"
);
});
o
.
clock
.
tick
(
1000
);
// include docs
o
.
allDocsResponse2
=
{};
o
.
allDocsResponse2
.
rows
=
[];
o
.
allDocsResponse2
.
total_rows
=
15
;
for
(
i
=
0
;
i
<
m
;
i
+=
1
)
{
o
.
allDocsResponse2
.
rows
.
push
({
"
id
"
:
""
+
i
,
"
key
"
:
""
+
i
,
"
value
"
:
{},
"
doc
"
:
localstorage
.
getItem
(
o
.
localpath
+
"
/
"
+
i
)
});
};
// alldocs
o
.
jio
.
allDocs
({
"
include_docs
"
:
true
},
function
(
e
,
r
)
{
var
x
=
r
.
rows
.
sort
(
o
.
sortArrayById
(
'
id
'
,
true
,
parseInt
));
deepEqual
(
{
"
total_rows
"
:
r
.
total_rows
,
"
rows
"
:
x
},
o
.
allDocsResponse2
,
"
AllDocs response generated from index (include docs)
"
);
});
o
.
clock
.
tick
(
1000
);
// complex queries
o
.
thisShouldBeTheAnswer4
=
[
{
"
title
"
:
"
Inceptions
"
,
"
year
"
:
2010
},
{
"
title
"
:
"
The Dark Knight
"
,
"
year
"
:
2008
},
{
"
title
"
:
"
Lord of the Rings - Return of the King
"
,
"
year
"
:
2003
},
{
"
title
"
:
"
Lord Of the Rings - Fellowship of the Ring
"
,
"
year
"
:
2001
},
{
"
title
"
:
"
Fight Club
"
,
"
year
"
:
1999
}
];
o
.
spy
(
o
,
"
value
"
,
o
.
thisShouldBeTheAnswer4
,
"
allDocs (complex queries year >= 1980, index used to do query)
"
);
o
.
jio
.
allDocs
({
"
query
"
:{
// "query":'(year: >= "1980" AND year: < "2000")',
"
query
"
:
'
(year: >= "1980")
'
,
"
filter
"
:
{
"
limit
"
:[
0
,
5
],
"
sort_on
"
:[[
'
year
'
,
'
descending
'
]],
"
select_list
"
:[
'
title
'
,
'
year
'
]
},
"
wildcard_character
"
:
'
%
'
}
},
o
.
f
);
o
.
tick
(
o
);
// complex queries
o
.
thisShouldBeTheAnswer5
=
[
{
"
director
"
:
"
Christopher Nolan
"
,
"
year
"
:
2010
},
{
"
director
"
:
"
Christopher Nolan
"
,
"
year
"
:
2008
},
{
"
director
"
:
"
Peter Jackson
"
,
"
year
"
:
2003
},
{
"
director
"
:
"
Peter Jackson
"
,
"
year
"
:
2001
},
{
"
director
"
:
"
David Fincher
"
,
"
year
"
:
1999
}
];
o
.
spy
(
o
,
"
value
"
,
o
.
thisShouldBeTheAnswer5
,
"
allDocs (complex queries year >= 1980, can't use index)
"
);
o
.
jio
.
allDocs
({
"
query
"
:{
// "query":'(year: >= "1980" AND year: < "2000")',
"
query
"
:
'
(year: >= "1980")
'
,
"
filter
"
:
{
"
limit
"
:[
0
,
5
],
"
sort_on
"
:[[
'
year
'
,
'
descending
'
]],
"
select_list
"
:[
'
director
'
,
'
year
'
]
},
"
wildcard_character
"
:
'
%
'
}
},
o
.
f
);
o
.
tick
(
o
);
o
.
jio
.
stop
();
});
});
/*
/*
module ('Jio CryptedStorage');
module ('Jio CryptedStorage');
...
...
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