Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio_mebibou
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
Alexandra Rogova
jio_mebibou
Commits
d9f1ea94
Commit
d9f1ea94
authored
Jul 25, 2019
by
Alexandra Rogova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
elasticlunrstorage repair updates documents
parent
b0f722a0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
167 additions
and
14 deletions
+167
-14
src/jio.storage/elasticlunrstorage.js
src/jio.storage/elasticlunrstorage.js
+44
-11
test/jio.storage/elasticlunrstorage.tests.js
test/jio.storage/elasticlunrstorage.tests.js
+120
-3
test/tests.html
test/tests.html
+3
-0
No files found.
src/jio.storage/elasticlunrstorage.js
View file @
d9f1ea94
...
...
@@ -67,7 +67,7 @@
});
index
.
setRef
(
id
);
// do not store the documents in the index
index
.
saveDocument
(
false
);
//
index.saveDocument(false);
return
index
;
}
...
...
@@ -100,18 +100,17 @@
boost
:
1
,
bool
:
'
AND
'
};
// we can only do a single-string search, so we can
// stop on the first indexed field we find
return
index
.
search
(
value
,
config
).
map
(
function
(
result
)
{
return
result
.
ref
;
});
}
return
null
;
}
function
recursiveIndexQuery
(
index
,
indexedFields
,
query
)
{
function
recursiveIndexQuery
(
index
,
indexedFields
,
query
,
sub_storage
)
{
var
ids
=
null
,
subquery
,
i
,
...
...
@@ -131,10 +130,9 @@
}
}
}
return
ids
;
}
return
searchQuery
(
index
,
indexedFields
,
query
.
key
,
query
.
value
);
}
...
...
@@ -303,7 +301,44 @@
ElasticlunrStorage
.
prototype
.
repair
=
function
()
{
// rebuild index?
return
this
.
_sub_storage
.
repair
.
apply
(
this
.
_sub_storage
,
arguments
);
var
idx
,
doc_ids
=
[],
context
=
this
,
args
=
arguments
;
return
this
.
_getIndex
()
.
push
(
function
(
index
){
idx
=
index
;
return
context
.
_sub_storage
.
repair
.
apply
(
context
.
_sub_storage
,
args
);
})
.
push
(
function
(){
return
context
.
_sub_storage
.
allDocs
();
})
.
push
(
function
(
all_docs
){
var
i
,
queue
=
new
RSVP
.
Queue
(),
add_to_queue
;
add_to_queue
=
function
(
id
){
queue
.
push
(
function
(){
return
context
.
_sub_storage
.
get
(
id
.
toString
());
})
.
push
(
function
(
doc
){
var
data
=
JSON
.
parse
(
JSON
.
stringify
(
doc
));
data
.
id
=
id
.
toString
();
idx
.
updateDoc
(
data
);
});
};
for
(
i
=
0
;
i
<
all_docs
.
data
.
rows
.
length
;
i
+=
1
){
add_to_queue
(
all_docs
.
data
.
rows
[
i
].
id
);
doc_ids
.
push
(
all_docs
.
data
.
rows
[
i
].
id
);
}
return
queue
;
})
.
push
(
undefined
,
function
(
my_error
)
{
if
(
my_error
.
status_code
===
501
)
{
//501 = sub_storage does not have allDocs capacity
//
}
else
throw
my_error
;
});
};
ElasticlunrStorage
.
prototype
.
hasCapacity
=
function
(
name
)
{
...
...
@@ -320,7 +355,7 @@
return
this
.
_sub_storage
.
hasCapacity
(
name
);
};
ElasticlunrStorage
.
prototype
.
buildQuery
=
function
(
options
)
{
ElasticlunrStorage
.
prototype
.
buildQuery
=
function
(
options
)
{
// Appelé par allDocs
var
context
=
this
,
indexedFields
=
this
.
_index_fields
,
runSubstorageQuery
=
options
.
select_list
||
options
.
include_docs
,
...
...
@@ -328,10 +363,9 @@
if
(
options
.
query
&&
options
.
query
.
indexOf
(
'
OR
'
)
===
-
1
)
{
parsedQuery
=
jIO
.
QueryFactory
.
create
(
options
.
query
);
return
context
.
_getIndex
()
.
push
(
function
(
index
)
{
return
recursiveIndexQuery
(
index
,
indexedFields
,
parsedQuery
);
return
recursiveIndexQuery
(
index
,
indexedFields
,
parsedQuery
,
context
.
_sub_storage
);
})
.
push
(
function
(
ids
)
{
try
{
...
...
@@ -352,7 +386,6 @@
if
(
runSubstorageQuery
)
{
return
context
.
_sub_storage
.
buildQuery
(
options
);
}
return
(
ids
||
[]).
map
(
function
(
id
)
{
return
{
id
:
id
,
...
...
test/jio.storage/elasticlunrstorage.tests.js
View file @
d9f1ea94
...
...
@@ -599,7 +599,7 @@
test
(
"
repair called substorage repair
"
,
function
()
{
stop
();
expect
(
2
);
//
expect(2);
Index200
.
prototype
.
getAttachment
=
function
()
{
return
true
;
...
...
@@ -620,10 +620,104 @@
deepEqual
(
options
,
expected_options
,
"
repair 200 called
"
);
return
"
OK
"
;
};
jio
.
repair
(
expected_options
)
.
then
(
function
(
result
)
{
/*
.then(function (result) {
equal(result, "OK");
})*/
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
repair adds missing documents
"
,
function
(){
stop
();
expect
(
2
);
Index200
.
prototype
.
getAttachment
=
function
()
{
return
true
;
};
var
sub_storage
=
jIO
.
createJIO
({
type
:
"
indexeddb
"
,
database
:
"
merge_test
"
}),
jio
=
jIO
.
createJIO
({
type
:
"
elasticlunr
"
,
index_fields
:
[
"
title
"
],
index_sub_storage
:
{
type
:
"
index200
"
},
sub_storage
:
{
type
:
"
indexeddb
"
,
database
:
"
merge_test
"
}
});
sub_storage
.
put
(
"
foo
"
,
{
title
:
"
bar
"
});
return
jio
.
repair
()
.
push
(
function
(){
return
jio
.
allDocs
({
query
:
'
title: "bar"
'
});
})
.
push
(
function
(
result
){
equal
(
result
.
data
.
total_rows
,
1
);
equal
(
result
.
data
.
rows
[
0
].
id
,
"
foo
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
repair updates documents
"
,
function
(){
expect
(
2
);
stop
();
Index200
.
prototype
.
getAttachment
=
function
()
{
return
true
;
};
Index200
.
prototype
.
putAttachment
=
function
()
{
return
true
;
};
var
sub_storage
=
jIO
.
createJIO
({
type
:
"
indexeddb
"
,
database
:
"
merge_test
"
}),
jio
=
jIO
.
createJIO
({
type
:
"
elasticlunr
"
,
index_fields
:
[
"
title
"
],
index_sub_storage
:
{
type
:
"
index200
"
},
sub_storage
:
{
type
:
"
indexeddb
"
,
database
:
"
merge_test
"
}
});
return
jio
.
put
(
"
foo
"
,
{
title
:
"
bar
"
})
.
push
(
function
(){
return
sub_storage
.
put
(
"
foo
"
,
{
title
:
"
Hello world!
"
});
})
.
push
(
function
(){
return
jio
.
repair
();
})
.
push
(
function
(){
return
jio
.
allDocs
({
query
:
'
title: "Hello world!"
'
});
})
.
push
(
function
(
result
){
equal
(
result
.
data
.
total_rows
,
1
);
equal
(
result
.
data
.
rows
[
0
].
id
,
"
foo
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
...
...
@@ -632,6 +726,29 @@
start
();
});
});
/*
test("repair deletes outdated documents", function(){
var sub_storage = jIO.createJIO({
type: "indexeddb",
database: "merge_test"
}),
jio = jIO.createJIO({
type: "elasticlunr",
index_fields: ["title"],
index_sub_storage: {
type: "index200"
},
sub_storage: {
type: "indexeddb",
database: "merge_test"
}
});
jio.put("foo", {title: "bar"});
sub_storage.remove("foo");
});
*/
/////////////////////////////////////////////////////////////////
// ElasticlunrStorage.buildQuery
...
...
test/tests.html
View file @
d9f1ea94
...
...
@@ -28,6 +28,9 @@ See https://www.nexedi.com/licensing for rationale and options.
<link
rel=
"stylesheet"
href=
"../external/qunit.css"
type=
"text/css"
media=
"screen"
/>
<script
src=
"../external/qunit.js"
type=
"text/javascript"
></script>
<script
src=
"../external/sinon.js"
type=
"text/javascript"
></script>
<!--<script src ="./elasticlunr.js"></script>
<script src="./elasticlunrstorage.js"></script>-->
<script>
QUnit
.
config
.
testTimeout
=
5000
;
...
...
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