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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Cédric Le Ninivin
jio
Commits
4685889d
Commit
4685889d
authored
Jan 28, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
indexStorage: pass jslint, prepare allDocs/complex queries
parent
9ca13f16
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
63 deletions
+82
-63
src/jio.storage/indexstorage.js
src/jio.storage/indexstorage.js
+82
-63
No files found.
src/jio.storage/indexstorage.js
View file @
4685889d
...
@@ -107,13 +107,20 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -107,13 +107,20 @@ jIO.addStorageType('indexed', function (spec, my) {
* @return {object} The new index array
* @return {object} The new index array
*/
*/
priv
.
createEmptyIndexArray
=
function
(
indices
)
{
priv
.
createEmptyIndexArray
=
function
(
indices
)
{
var
i
,
j
=
priv
.
indices
.
length
,
var
i
,
k
,
j
=
priv
.
indices
.
length
,
new_index
,
new_index_object
=
{},
new_index_name
;
new_index_object
=
{},
new_index_name
,
new_index_fields
;
if
(
indices
===
undefined
)
{
if
(
indices
===
undefined
)
{
for
(
i
=
0
;
i
<
j
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
j
;
i
+=
1
)
{
new_index_name
=
priv
.
indices
[
i
].
name
;
new_index
=
priv
.
indices
[
i
];
new_index_name
=
new_index
.
name
;
new_index_fields
=
new_index
.
fields
;
new_index_object
[
new_index_name
]
=
{};
new_index_object
[
new_index_name
]
=
{};
// loop index fields and add objects to hold value/id pairs
for
(
k
=
0
;
k
<
new_index_fields
.
length
;
k
+=
1
)
{
new_index_object
[
new_index_name
][
new_index_fields
[
k
]]
=
{};
}
}
}
}
}
return
new_index_object
;
return
new_index_object
;
...
@@ -168,21 +175,27 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -168,21 +175,27 @@ jIO.addStorageType('indexed', function (spec, my) {
* @return {boolean} true/false
* @return {boolean} true/false
*/
*/
priv
.
isDocidInIndex
=
function
(
indices
,
doc
)
{
priv
.
isDocidInIndex
=
function
(
indices
,
doc
)
{
var
index
,
i
,
l
=
priv
.
indices
.
length
;
var
index
,
i
,
j
,
label
,
l
=
priv
.
indices
.
length
;
// loop indices
// loop indices
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
index
=
{};
index
=
{};
index
.
reference
=
priv
.
indices
[
i
];
index
.
reference
=
priv
.
indices
[
i
];
index
.
name
=
index
.
reference
.
name
;
index
.
reference_size
=
index
.
reference
.
fields
.
length
;
index
.
size
=
priv
.
getObjectSize
(
indices
[
index
.
name
]);
index
.
current
=
indices
[
index
.
reference
.
name
];
for
(
j
=
0
;
j
<
index
.
reference_size
;
j
+=
1
)
{
label
=
index
.
reference
.
fields
[
j
];
index
.
current_size
=
priv
.
getObjectSize
(
index
.
current
[
label
]);
if
(
index
.
size
>
0
)
{
// check for existing entries to remove (put-update)
if
(
priv
.
searchIndexByValue
(
indices
[
index
.
name
],
doc
.
_id
,
"
bool
"
))
{
if
(
index
.
current_size
>
0
)
{
if
(
priv
.
searchIndexByValue
(
index
.
current
[
label
],
doc
.
_id
,
"
bool
"
))
{
return
true
;
return
true
;
}
}
}
}
}
}
}
return
false
;
return
false
;
};
};
...
@@ -194,26 +207,32 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -194,26 +207,32 @@ jIO.addStorageType('indexed', function (spec, my) {
* @return {object} indices The cleaned up file
* @return {object} indices The cleaned up file
*/
*/
priv
.
cleanIndices
=
function
(
indices
,
doc
)
{
priv
.
cleanIndices
=
function
(
indices
,
doc
)
{
var
i
,
j
,
k
,
index
,
key
,
l
=
priv
.
indices
.
length
;
var
i
,
j
,
k
,
index
,
key
,
l
abel
,
l
=
priv
.
indices
.
length
;
// loop indices (indexA, indexAB...)
// loop indices (indexA, indexAB...)
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
// index object (reference and current-iteration)
index
=
{};
index
=
{};
index
.
reference
=
priv
.
indices
[
i
];
index
.
reference
=
priv
.
indices
[
i
];
index
.
reference_size
=
index
.
reference
.
fields
.
length
;
index
.
current
=
indices
[
index
.
reference
.
name
];
index
.
current
=
indices
[
index
.
reference
.
name
];
index
.
current_size
=
priv
.
getObjectSize
(
index
.
current
);
for
(
j
=
0
;
j
<
index
.
current_size
;
j
+=
1
)
{
// loop index fields
key
=
priv
.
searchIndexByValue
(
index
.
current
,
doc
.
_id
,
"
key
"
);
for
(
j
=
0
;
j
<
index
.
reference_size
;
j
+=
1
)
{
index
.
result_array
=
index
.
current
[
key
];
label
=
index
.
reference
.
fields
[
j
];
index
.
current_size
=
priv
.
getObjectSize
(
index
.
current
[
label
]);
// loop field entries
for
(
k
=
0
;
k
<
index
.
current_size
;
k
+=
1
)
{
key
=
priv
.
searchIndexByValue
(
index
.
current
[
label
],
doc
.
_id
,
"
key
"
);
index
.
result_array
=
index
.
current
[
label
][
key
];
if
(
!!
key
)
{
if
(
!!
key
)
{
// if there is more than one docid in the result array,
// if there is more than one docid in the result array,
// just remove this one and not the whole array
// just remove this one and not the whole array
if
(
index
.
result_array
.
length
>
1
)
{
if
(
index
.
result_array
.
length
>
1
)
{
index
.
result_array
.
splice
(
k
,
1
);
index
.
result_array
.
splice
(
k
,
1
);
}
else
{
}
else
{
delete
index
.
current
[
key
];
delete
index
.
current
[
label
][
key
];
}
}
}
}
}
}
}
...
@@ -227,47 +246,38 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -227,47 +246,38 @@ jIO.addStorageType('indexed', function (spec, my) {
* @param {object} doc The document which should be added to the index
* @param {object} doc The document which should be added to the index
*/
*/
priv
.
updateIndices
=
function
(
indices
,
doc
)
{
priv
.
updateIndices
=
function
(
indices
,
doc
)
{
var
i
,
j
,
k
,
m
,
index
,
value
,
label
,
key
,
l
=
priv
.
indices
.
length
;
var
i
,
j
,
index
,
value
,
label
,
key
,
l
=
priv
.
indices
.
length
;
// loop indices
// loop indices
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
// index object (reference and current-iteration)
index
=
{};
index
=
{};
index
.
reference
=
priv
.
indices
[
i
];
index
.
reference
=
priv
.
indices
[
i
];
index
.
reference_size
=
index
.
reference
.
fields
.
length
;
index
.
reference_size
=
index
.
reference
.
fields
.
length
;
index
.
field_array
=
[];
index
.
current
=
indices
[
index
.
reference
.
name
];
index
.
current
=
indices
[
index
.
reference
.
name
];
index
.
current_size
=
priv
.
getObjectSize
(
index
.
current
);
// build array of values to create entries in index
// build array of values to create entries in index
for
(
j
=
0
;
j
<
index
.
reference_size
;
j
+=
1
)
{
for
(
j
=
0
;
j
<
index
.
reference_size
;
j
+=
1
)
{
label
=
index
.
reference
.
fields
[
j
];
label
=
index
.
reference
.
fields
[
j
];
value
=
doc
[
label
];
value
=
doc
[
label
];
if
(
value
!==
undefined
)
{
if
(
value
!==
undefined
)
{
// add a new entry
index
.
current_size
=
priv
.
getObjectSize
(
index
.
current
[
label
]);
index
.
field_array
.
push
(
value
);
//
remove existing entries with same docid (put-update!
)
//
check for existing entries to remove (put-update
)
if
(
index
.
current_size
>
0
)
{
if
(
index
.
current_size
>
0
)
{
key
=
priv
.
searchIndexByValue
(
indices
[
index
.
reference
.
name
],
key
=
priv
.
searchIndexByValue
(
doc
.
_id
,
"
key
"
);
index
.
current
[
label
],
doc
.
_id
,
"
key
"
);
if
(
!!
key
)
{
if
(
!!
key
)
{
delete
index
.
current
[
key
];
delete
index
.
current
[
label
][
key
];
}
}
}
}
}
if
(
index
.
current
[
label
][
value
]
===
undefined
)
{
index
.
current
[
label
][
value
]
=
[];
}
}
// create keyword entries
// add a new entry
if
(
index
.
current
!==
undefined
)
{
index
.
current
[
label
][
value
].
push
(
doc
.
_id
);
m
=
index
.
field_array
.
length
;
if
(
m
)
{
for
(
k
=
0
;
k
<
m
;
k
+=
1
)
{
index
.
current_keyword
=
[
index
.
field_array
[
k
]];
if
(
index
.
current
[
index
.
current_keyword
]
===
undefined
)
{
index
.
current
[
index
.
current_keyword
]
=
[];
}
index
.
current
[
index
.
current_keyword
].
push
(
doc
.
_id
);
}
}
}
}
}
}
}
...
@@ -366,7 +376,6 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -366,7 +376,6 @@ jIO.addStorageType('indexed', function (spec, my) {
*/
*/
priv
.
convertIndicesToQueryObject
=
function
(
indices
,
query_syntax
)
{
priv
.
convertIndicesToQueryObject
=
function
(
indices
,
query_syntax
)
{
var
use_index
=
priv
.
findBestIndexForQuery
(
indices
,
query_syntax
);
var
use_index
=
priv
.
findBestIndexForQuery
(
indices
,
query_syntax
);
return
indices
;
return
indices
;
};
};
/**
/**
...
@@ -379,7 +388,7 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -379,7 +388,7 @@ jIO.addStorageType('indexed', function (spec, my) {
*/
*/
priv
.
allDocsResponseFromIndex
=
function
(
indices
,
include_docs
,
option
)
{
priv
.
allDocsResponseFromIndex
=
function
(
indices
,
include_docs
,
option
)
{
var
i
,
j
,
k
,
m
,
n
=
0
,
l
=
priv
.
indices
.
length
,
var
i
,
j
,
k
,
m
,
n
=
0
,
l
=
priv
.
indices
.
length
,
index
,
key
,
obj
,
prop
,
found
,
file
,
index
,
key
,
obj
,
prop
,
found
,
file
,
label
,
unique_count
=
0
,
unique_docids
=
[],
all_doc_response
=
{},
unique_count
=
0
,
unique_docids
=
[],
all_doc_response
=
{},
success
=
function
(
content
)
{
success
=
function
(
content
)
{
file
=
{
value
:
{}
};
file
=
{
value
:
{}
};
...
@@ -408,14 +417,21 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -408,14 +417,21 @@ jIO.addStorageType('indexed', function (spec, my) {
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
index
=
{};
index
=
{};
index
.
reference
=
priv
.
indices
[
i
];
index
.
reference
=
priv
.
indices
[
i
];
index
.
reference_size
=
index
.
reference
.
fields
.
length
;
index
.
current
=
indices
[
index
.
reference
.
name
];
index
.
current
=
indices
[
index
.
reference
.
name
];
index
.
current_size
=
priv
.
getObjectSize
(
index
.
current
);
// a lot of loops, not sure this is the fastest way
// a lot of loops, not sure this is the fastest way
// loop index fields
for
(
j
=
0
;
j
<
index
.
reference_size
;
j
+=
1
)
{
label
=
index
.
reference
.
fields
[
j
];
index
.
current_field
=
index
.
current
[
label
];
index
.
current_size
=
priv
.
getObjectSize
(
index
.
current_field
);
// loop field id array
for
(
j
=
0
;
j
<
index
.
current_size
;
j
+=
1
)
{
for
(
j
=
0
;
j
<
index
.
current_size
;
j
+=
1
)
{
for
(
key
in
index
.
current
)
{
for
(
key
in
index
.
current_field
)
{
if
(
index
.
current
.
hasOwnProperty
(
key
))
{
if
(
index
.
current_field
.
hasOwnProperty
(
key
))
{
obj
=
index
.
current
[
key
];
obj
=
index
.
current_field
[
key
];
for
(
prop
in
obj
)
{
for
(
prop
in
obj
)
{
if
(
obj
.
hasOwnProperty
(
prop
))
{
if
(
obj
.
hasOwnProperty
(
prop
))
{
for
(
k
=
0
;
k
<
unique_docids
.
length
;
k
+=
1
)
{
for
(
k
=
0
;
k
<
unique_docids
.
length
;
k
+=
1
)
{
...
@@ -434,6 +450,8 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -434,6 +450,8 @@ jIO.addStorageType('indexed', function (spec, my) {
}
}
}
}
}
}
}
// construct allDocs response
// construct allDocs response
all_doc_response
.
total_rows
=
unique_count
;
all_doc_response
.
total_rows
=
unique_count
;
all_doc_response
.
rows
=
[];
all_doc_response
.
rows
=
[];
...
@@ -771,6 +789,7 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -771,6 +789,7 @@ jIO.addStorageType('indexed', function (spec, my) {
priv
.
index_suffix
,
priv
.
index_suffix
,
option
,
option
,
function
(
response
)
{
function
(
response
)
{
// should include_docs be possible besides complex queries?
query_syntax
=
command
.
getOption
(
'
query
'
);
query_syntax
=
command
.
getOption
(
'
query
'
);
if
(
query_syntax
!==
undefined
)
{
if
(
query_syntax
!==
undefined
)
{
// check to see if index can do the job
// check to see if index can do the job
...
...
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