Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Commit

Permalink
Allow for implicit placeholder bindings in fulltext.
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Newman committed Jun 14, 2017
1 parent 5074d48 commit 647d9d7
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions query-algebrizer/src/clauses/fulltext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ impl ConjoiningClauses {
// We should have exactly four bindings. Destructure them now.
let bindings = match where_fn.binding {
Binding::BindRel(bindings) => {
if bindings.len() != 4 {
let bindings_count = bindings.len();
if bindings_count < 1 || bindings_count > 4 {
bail!(ErrorKind::InvalidBinding(where_fn.operator.clone(),
BindingError::InvalidNumberOfBindings {
number: bindings.len(),
Expand All @@ -80,9 +81,9 @@ impl ConjoiningClauses {
};
let mut bindings = bindings.into_iter();
let b_entity = bindings.next().unwrap();
let b_value = bindings.next().unwrap();
let b_tx = bindings.next().unwrap();
let b_score = bindings.next().unwrap();
let b_value = bindings.next().unwrap_or(VariableOrPlaceholder::Placeholder);
let b_tx = bindings.next().unwrap_or(VariableOrPlaceholder::Placeholder);
let b_score = bindings.next().unwrap_or(VariableOrPlaceholder::Placeholder);

let mut args = where_fn.args.into_iter();

Expand Down Expand Up @@ -172,8 +173,8 @@ impl ConjoiningClauses {
_ => bail!(ErrorKind::InvalidArgument(where_fn.operator.clone(), "string".into(), 2)),
};

// TODO: should we build the FQA in ::Matches, preventing nonsense like matching on ::Rowid?
let constraint = ColumnConstraint::Matches(QualifiedAlias(fulltext_values_alias.clone(), Column::Fulltext(FulltextColumn::Text)),
let constraint = ColumnConstraint::Matches(QualifiedAlias(fulltext_values_alias.clone(),
Column::Fulltext(FulltextColumn::Text)),
QueryValue::TypedValue(search));
self.wheres.add_intersection(constraint);

Expand All @@ -198,6 +199,7 @@ impl ConjoiningClauses {
}

if let VariableOrPlaceholder::Variable(ref var) = b_tx {
// Txs must be refs.
self.constrain_var_to_type(var.clone(), ValueType::Ref);
if self.is_known_empty() {
return Ok(());
Expand All @@ -207,14 +209,15 @@ impl ConjoiningClauses {
}

if let VariableOrPlaceholder::Variable(ref var) = b_score {
// Scores are doubles.
self.constrain_var_to_type(var.clone(), ValueType::Double);

// We do not allow the score to be bound.
if self.value_bindings.contains_key(var) || self.input_variables.contains(var) {
bail!(ErrorKind::InvalidBinding(var.name(), BindingError::UnexpectedBinding));
}

// We bind the value ourselves. This takes care of substituting into existing uses.
// We bind the value ourselves. This handily takes care of substituting into existing uses.
// TODO: produce real scores using SQLite's matchinfo.
self.bind_value(var, TypedValue::Double(0.0.into()));
}
Expand Down

0 comments on commit 647d9d7

Please sign in to comment.