Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding facet filter and search #21

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tantivy"
version = "0.13.2"
version = "0.14.0"
Copy link
Contributor

@poljar poljar Apr 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the tantivy upgrade should be a separate PR, or is there something this PR needs from 0.14?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using this branch on prod, I can do a new PR for the 0.14 if its better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please, separate PR for the 0.14 bump would be nice.

readme = "README.md"
authors = ["Damir Jelić <[email protected]>"]
edition = "2018"
Expand All @@ -12,7 +12,7 @@ crate-type = ["cdylib"]

[dependencies]
chrono = "0.4.19"
tantivy = "0.13.2"
tantivy = "0.14"
itertools = "0.9.0"
futures = "0.3.5"

Expand Down
2 changes: 1 addition & 1 deletion src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl Index {
#[staticmethod]
fn exists(path: &str) -> PyResult<bool> {
let directory = MmapDirectory::open(path).map_err(to_pyerr)?;
Ok(tv::Index::exists(&directory))
Ok(tv::Index::exists(&directory).unwrap())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should panic for IO errors.

}

/// The schema of the current index.
Expand Down
25 changes: 23 additions & 2 deletions src/schemabuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,18 @@ impl SchemaBuilder {
///
/// Args:
/// name (str): The name of the field.
fn add_bytes_field(&mut self, name: &str) -> PyResult<Self> {
fn add_bytes_field(
&mut self,
name: &str,
stored: bool,
indexed: bool,
fast: bool,
) -> PyResult<Self> {
let builder = &mut self.builder;
let opts = SchemaBuilder::build_bytes_option(stored, indexed, fast)?;

if let Some(builder) = builder.write().unwrap().as_mut() {
builder.add_bytes_field(name);
builder.add_bytes_field(name, opts);
} else {
return Err(exceptions::PyValueError::new_err(
"Schema builder object isn't valid anymore.",
Expand Down Expand Up @@ -316,4 +323,18 @@ impl SchemaBuilder {

Ok(opts)
}

fn build_bytes_option(
stored: bool,
indexed: bool,
fast: bool,
) -> PyResult<schema::BytesOptions> {
let opts = schema::BytesOptions::default();

let opts = if stored { opts.set_stored() } else { opts };
let opts = if indexed { opts.set_indexed() } else { opts };
let opts = if fast { opts.set_fast() } else { opts };

Ok(opts)
}
}
5 changes: 2 additions & 3 deletions src/searcher.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#![allow(clippy::new_ret_no_self)]

use pyo3::exceptions::ValueError;
use pyo3::types::{PyDict, PyList, PyTuple};
use std::collections::BTreeMap;
use crate::{document::Document, get_field, query::Query, to_pyerr};
use pyo3::types::{PyDict, PyList, PyTuple};
use pyo3::{exceptions::PyValueError, prelude::*, PyObjectProtocol};
use std::collections::BTreeMap;
use tantivy as tv;
use tantivy::collector::{Count, MultiCollector, TopDocs};

Expand Down