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
Roque
jio
Commits
16a96d68
Commit
16a96d68
authored
Aug 03, 2017
by
preetwinder
Committed by
Romain Courteaud
Aug 10, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add full text searh as default if key isn't specified
/reviewed-on
nexedi/jio!62
parent
086d8dd9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
121 additions
and
4 deletions
+121
-4
src/queries/build/parser.js
src/queries/build/parser.js
+1
-1
src/queries/core/parser.par
src/queries/core/parser.par
+1
-1
src/queries/query.js
src/queries/query.js
+18
-1
test/queries/tests.js
test/queries/tests.js
+101
-1
No files found.
src/queries/build/parser.js
View file @
16a96d68
...
...
@@ -90,7 +90,7 @@ case 5: case 8: case 11: case 14: case 16:
this
.
$
=
$$
[
$0
];
break
;
case
6
:
this
.
$
=
mkComplexQuery
(
'
OR
'
,
[
$$
[
$0
-
1
],
$$
[
$0
]]);
this
.
$
=
mkComplexQuery
(
'
AND
'
,
[
$$
[
$0
-
1
],
$$
[
$0
]]);
break
;
case
7
:
this
.
$
=
mkComplexQuery
(
'
OR
'
,
[
$$
[
$0
-
2
],
$$
[
$0
]]);
...
...
src/queries/core/parser.par
View file @
16a96d68
...
...
@@ -45,7 +45,7 @@ end
search_text
: and_expression { $$ = $1; }
| and_expression search_text { $$ = mkComplexQuery('
OR
', [$1, $2]); }
| and_expression search_text { $$ = mkComplexQuery('
AND
', [$1, $2]); }
| and_expression OR search_text { $$ = mkComplexQuery('OR', [$1, $3]); }
;
...
...
src/queries/query.js
View file @
16a96d68
...
...
@@ -717,7 +717,8 @@
matchMethod
=
null
,
operator
=
this
.
operator
,
value
=
null
,
key
=
this
.
key
;
key
=
this
.
key
,
k
;
if
(
!
(
regexp_comparaison
.
test
(
operator
)))
{
// `operator` is not correct, we have to change it to "like" or "="
...
...
@@ -736,6 +737,22 @@
key
=
this
.
_key_schema
.
key_set
[
key
];
}
// match with all the fields if key is empty
if
(
key
===
''
)
{
matchMethod
=
this
.
like
;
value
=
'
%
'
+
this
.
value
+
'
%
'
;
for
(
k
in
item
)
{
if
(
item
.
hasOwnProperty
(
k
))
{
if
(
k
!==
'
__id
'
)
{
if
(
matchMethod
(
item
[
k
],
value
)
===
true
)
{
return
true
;
}
}
}
}
return
false
;
}
if
(
typeof
key
===
'
object
'
)
{
checkKey
(
key
);
object_value
=
item
[
key
.
read_from
];
...
...
test/queries/tests.js
View file @
16a96d68
...
...
@@ -154,7 +154,8 @@
.
exec
(
doc_list
);
})
.
then
(
function
(
doc_list
)
{
deepEqual
(
doc_list
,
[],
'
No document should be kept
'
);
deepEqual
(
doc_list
,
[{
"
identifier
"
:
"
测试一
"
,
"
title
"
:
"
标题
"
}
],
'
Full text query matched document should be returned
'
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
...
...
@@ -357,4 +358,103 @@
],
'
Documents with newlines are matched
'
);
}).
always
(
start
);
});
test
(
'
Default operator for complex query
'
,
function
()
{
var
doc_list
=
[
{
"
identifier
"
:
"
a
"
,
"
value
"
:
"
test1
"
,
"
time
"
:
"
2016
"
},
{
"
identifier
"
:
"
a
"
,
"
value
"
:
"
test
"
,
"
time
"
:
"
2016
"
},
{
"
identifier
"
:
"
c
"
,
"
value
"
:
"
test1
"
,
"
time
"
:
"
2017
"
}
];
stop
();
expect
(
1
);
jIO
.
QueryFactory
.
create
(
'
identifier:%a% value:"%test1%" time:%2016%
'
)
.
exec
(
doc_list
)
.
then
(
function
(
doc_list
)
{
deepEqual
(
doc_list
,
[
{
"
identifier
"
:
"
a
"
,
"
value
"
:
"
test1
"
,
"
time
"
:
"
2016
"
}],
'
Document which matches all the fields is matched
'
);
}).
always
(
start
);
});
test
(
'
Full text query with single word
'
,
function
()
{
var
doc_list
=
[
{
"
identifier
"
:
"
a
"
,
"
value
"
:
"
test
"
,
"
time
"
:
"
2016
"
},
{
"
identifier
"
:
"
b
"
,
"
value
"
:
"
test 1
"
,
"
time
"
:
"
2017
"
},
{
"
identifier
"
:
"
c
"
,
"
value
"
:
"
test 2016
"
,
"
time
"
:
"
2017
"
}
];
stop
();
expect
(
2
);
jIO
.
QueryFactory
.
create
(
'
test
'
).
exec
(
doc_list
).
then
(
function
(
doc_list
)
{
deepEqual
(
doc_list
,
[
{
"
identifier
"
:
"
a
"
,
"
value
"
:
"
test
"
,
"
time
"
:
"
2016
"
},
{
"
identifier
"
:
"
b
"
,
"
value
"
:
"
test 1
"
,
"
time
"
:
"
2017
"
},
{
"
identifier
"
:
"
c
"
,
"
value
"
:
"
test 2016
"
,
"
time
"
:
"
2017
"
}
],
'
Documents which have test in any column are matched
'
);
doc_list
=
[
{
"
identifier
"
:
"
a
"
,
"
value
"
:
"
test
"
,
"
time
"
:
"
2016
"
},
{
"
identifier
"
:
"
b
"
,
"
value
"
:
"
test 1
"
,
"
time
"
:
"
2017
"
},
{
"
identifier
"
:
"
c
"
,
"
value
"
:
"
test 2016
"
,
"
time
"
:
"
2017
"
}
];
return
jIO
.
QueryFactory
.
create
(
'
2016
'
).
exec
(
doc_list
).
then
(
function
(
doc_list
)
{
deepEqual
(
doc_list
,
[
{
"
identifier
"
:
"
a
"
,
"
value
"
:
"
test
"
,
"
time
"
:
"
2016
"
},
{
"
identifier
"
:
"
c
"
,
"
value
"
:
"
test 2016
"
,
"
time
"
:
"
2017
"
}
],
'
Documents which have 2016 in any column are matched
'
);
}).
always
(
start
);
});
});
test
(
'
Full text query with multiple words
'
,
function
()
{
var
doc_list
=
[
{
"
identifier
"
:
"
a
"
,
"
value
"
:
"
test post
"
,
"
time
"
:
"
2016
"
},
{
"
identifier
"
:
"
b
"
,
"
value
"
:
"
test post 1
"
,
"
time
"
:
"
2017
"
},
{
"
identifier
"
:
"
c
"
,
"
value
"
:
"
test post 2016
"
,
"
time
"
:
"
2017
"
}
];
stop
();
expect
(
2
);
jIO
.
QueryFactory
.
create
(
'
test post
'
).
exec
(
doc_list
).
then
(
function
(
doc_list
)
{
deepEqual
(
doc_list
,
[
{
"
identifier
"
:
"
a
"
,
"
value
"
:
"
test post
"
,
"
time
"
:
"
2016
"
},
{
"
identifier
"
:
"
b
"
,
"
value
"
:
"
test post 1
"
,
"
time
"
:
"
2017
"
},
{
"
identifier
"
:
"
c
"
,
"
value
"
:
"
test post 2016
"
,
"
time
"
:
"
2017
"
}
],
'
Documents which have test post in any column are matched
'
);
doc_list
=
[
{
"
identifier
"
:
"
a
"
,
"
value
"
:
"
test post
"
,
"
time
"
:
"
2016
"
},
{
"
identifier
"
:
"
b
"
,
"
value
"
:
"
test post 1
"
,
"
time
"
:
"
2017
"
},
{
"
identifier
"
:
"
c
"
,
"
value
"
:
"
test post 2016
"
,
"
time
"
:
"
2017
"
}
];
return
jIO
.
QueryFactory
.
create
(
'
test post 2016
'
).
exec
(
doc_list
).
then
(
function
(
doc_list
)
{
deepEqual
(
doc_list
,
[
{
"
identifier
"
:
"
a
"
,
"
value
"
:
"
test post
"
,
"
time
"
:
"
2016
"
},
{
"
identifier
"
:
"
c
"
,
"
value
"
:
"
test post 2016
"
,
"
time
"
:
"
2017
"
}
],
'
Documents which have test post 2016 in any column are matched
'
);
}).
always
(
start
);
});
});
// Asterisk wildcard is not supported yet.
/* test('Full text query with asterisk', function () {
var doc_list = [
{"identifier": "abc"},
{"identifier": "ab"}
];
stop();
expect(1);
jIO.QueryFactory.create('a*').exec(doc_list).
then(function (doc_list) {
deepEqual(doc_list, [
{"identifier": "abc"},
{"identifier": "ab"}
], 'Documents which satisfy the asterisk wildcard should be returned')
.always(start);
});
});*/
}));
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