Skip to content

Commit

Permalink
Allow range queries via fast fields on non-indexed fields
Browse files Browse the repository at this point in the history
  • Loading branch information
guilload committed Jan 10, 2023
1 parent 14222a4 commit 3dd3933
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/query/query_parser/query_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,7 @@ impl QueryParser {
let field_entry = self.schema.get_field_entry(field);
let field_type = field_entry.field_type();

let is_ip_and_fast = field_type.is_ip_addr() && field_type.is_fast();
if !field_type.is_indexed() && !is_ip_and_fast {
if !field_type.is_indexed() && !supports_ff_range_queries(&field_type) {
return Err(QueryParserError::FieldNotIndexed(
field_entry.name().to_string(),
));
Expand Down Expand Up @@ -847,6 +846,15 @@ fn convert_to_query(fuzzy: &FxHashMap<Field, Fuzzy>, logical_ast: LogicalAst) ->
}
}

fn supports_ff_range_queries(field_type: &FieldType) -> bool {
match field_type {
FieldType::Date(_) | FieldType::IpAddr(_) | FieldType::U64(_) if field_type.is_fast() => {
true
}
_ => false,
}
}

#[cfg(test)]
mod test {
use matches::assert_matches;
Expand All @@ -855,7 +863,7 @@ mod test {
use super::{QueryParser, QueryParserError};
use crate::query::Query;
use crate::schema::{
FacetOptions, Field, IndexRecordOption, Schema, Term, TextFieldIndexing, TextOptions,
FacetOptions, Field, IndexRecordOption, Schema, Term, TextFieldIndexing, TextOptions, FAST,
INDEXED, STORED, STRING, TEXT,
};
use crate::tokenizer::{
Expand Down Expand Up @@ -889,6 +897,7 @@ mod test {
schema_builder.add_json_field("json_not_indexed", STORED);
schema_builder.add_bool_field("bool", INDEXED);
schema_builder.add_bool_field("notindexed_bool", STORED);
schema_builder.add_u64_field("u64_ff", FAST);
schema_builder.build()
}

Expand Down Expand Up @@ -1344,6 +1353,11 @@ mod test {
r#"(Excluded(Term(type=F64, field=10, -1.5)) TO Excluded(Term(type=F64, field=10, 1.5)))"#,
false,
);
test_parse_query_to_logical_ast_helper(
"u64_ff:[7 TO 77]",
r#"(Included(Term(type=U64, field=18, 7)) TO Included(Term(type=U64, field=18, 77)))"#,
false,
);
}

#[test]
Expand Down

0 comments on commit 3dd3933

Please sign in to comment.