2017-06-12 21:19:35 +00:00
|
|
|
// Copyright 2016 Mozilla
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
|
|
// this file except in compliance with the License. You may obtain a copy of the
|
|
|
|
// License at http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
// Unless required by applicable law or agreed to in writing, software distributed
|
|
|
|
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
|
|
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
|
|
// specific language governing permissions and limitations under the License.
|
|
|
|
|
|
|
|
extern crate mentat_core;
|
|
|
|
extern crate mentat_query;
|
|
|
|
extern crate mentat_query_algebrizer;
|
|
|
|
|
2018-01-29 22:29:16 +00:00
|
|
|
mod utils;
|
|
|
|
|
2017-06-12 21:19:35 +00:00
|
|
|
use mentat_core::{
|
|
|
|
Attribute,
|
|
|
|
Schema,
|
|
|
|
ValueType,
|
|
|
|
};
|
|
|
|
|
|
|
|
use mentat_query::{
|
2018-05-11 16:52:17 +00:00
|
|
|
Keyword,
|
2017-06-12 21:19:35 +00:00
|
|
|
};
|
|
|
|
|
2018-01-29 22:29:16 +00:00
|
|
|
use utils::{
|
|
|
|
add_attribute,
|
|
|
|
alg,
|
|
|
|
associate_ident,
|
2017-06-12 21:19:35 +00:00
|
|
|
};
|
|
|
|
|
2018-02-14 00:51:21 +00:00
|
|
|
use mentat_query_algebrizer::Known;
|
|
|
|
|
2017-06-12 21:19:35 +00:00
|
|
|
fn prepopulated_schema() -> Schema {
|
|
|
|
let mut schema = Schema::default();
|
2018-05-11 16:52:17 +00:00
|
|
|
associate_ident(&mut schema, Keyword::namespaced("foo", "name"), 65);
|
|
|
|
associate_ident(&mut schema, Keyword::namespaced("foo", "description"), 66);
|
|
|
|
associate_ident(&mut schema, Keyword::namespaced("foo", "parent"), 67);
|
|
|
|
associate_ident(&mut schema, Keyword::namespaced("foo", "age"), 68);
|
|
|
|
associate_ident(&mut schema, Keyword::namespaced("foo", "height"), 69);
|
2017-06-12 21:19:35 +00:00
|
|
|
add_attribute(&mut schema, 65, Attribute {
|
|
|
|
value_type: ValueType::String,
|
|
|
|
multival: false,
|
|
|
|
..Default::default()
|
|
|
|
});
|
|
|
|
add_attribute(&mut schema, 66, Attribute {
|
|
|
|
value_type: ValueType::String,
|
2018-02-01 17:06:01 +00:00
|
|
|
index: true,
|
2017-06-12 21:19:35 +00:00
|
|
|
fulltext: true,
|
|
|
|
multival: true,
|
|
|
|
..Default::default()
|
|
|
|
});
|
|
|
|
add_attribute(&mut schema, 67, Attribute {
|
|
|
|
value_type: ValueType::String,
|
|
|
|
multival: true,
|
|
|
|
..Default::default()
|
|
|
|
});
|
|
|
|
add_attribute(&mut schema, 68, Attribute {
|
|
|
|
value_type: ValueType::Long,
|
|
|
|
multival: false,
|
|
|
|
..Default::default()
|
|
|
|
});
|
|
|
|
add_attribute(&mut schema, 69, Attribute {
|
|
|
|
value_type: ValueType::Long,
|
|
|
|
multival: false,
|
|
|
|
..Default::default()
|
|
|
|
});
|
|
|
|
schema
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_apply_fulltext() {
|
|
|
|
let schema = prepopulated_schema();
|
2018-02-14 00:51:21 +00:00
|
|
|
let known = Known::for_schema(&schema);
|
2017-06-12 21:19:35 +00:00
|
|
|
|
|
|
|
// If you use a non-FTS attribute, we will short-circuit.
|
|
|
|
let query = r#"[:find ?val
|
|
|
|
:where [(fulltext $ :foo/name "hello") [[?entity ?val _ _]]]]"#;
|
2018-02-14 00:51:21 +00:00
|
|
|
assert!(alg(known, query).is_known_empty());
|
2017-06-12 21:19:35 +00:00
|
|
|
|
|
|
|
// If you get a type mismatch, we will short-circuit.
|
|
|
|
let query = r#"[:find ?val
|
|
|
|
:where [(fulltext $ :foo/description "hello") [[?entity ?val ?tx ?score]]]
|
|
|
|
[?score :foo/bar _]]"#;
|
2018-02-14 00:51:21 +00:00
|
|
|
assert!(alg(known, query).is_known_empty());
|
2017-06-12 21:19:35 +00:00
|
|
|
}
|