Compare commits

..

No commits in common. "2671a3b787aabf5e87e3a149abb9f0ccb4b6d521" and "88f8a9d53725460fe49cd81ce6053447b6e9f62e" have entirely different histories.

8 changed files with 38 additions and 40 deletions

10
Cargo.lock generated
View File

@ -2469,7 +2469,7 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "letterbox"
version = "0.0.52"
version = "0.0.51"
dependencies = [
"build-info",
"build-info-build",
@ -2988,7 +2988,7 @@ dependencies = [
[[package]]
name = "notmuch"
version = "0.0.52"
version = "0.0.51"
dependencies = [
"itertools 0.10.5",
"log",
@ -3625,7 +3625,7 @@ dependencies = [
[[package]]
name = "procmail2notmuch"
version = "0.0.52"
version = "0.0.51"
dependencies = [
"anyhow",
]
@ -4547,7 +4547,7 @@ dependencies = [
[[package]]
name = "server"
version = "0.0.52"
version = "0.0.51"
dependencies = [
"ammonia",
"anyhow",
@ -4646,7 +4646,7 @@ dependencies = [
[[package]]
name = "shared"
version = "0.0.52"
version = "0.0.51"
dependencies = [
"build-info",
"notmuch",

View File

@ -1,6 +1,6 @@
[package]
name = "notmuch"
version = "0.0.52"
version = "0.0.51"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -1,6 +1,6 @@
[package]
name = "procmail2notmuch"
version = "0.0.52"
version = "0.0.51"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -1,6 +1,6 @@
[package]
name = "server"
version = "0.0.52"
version = "0.0.51"
edition = "2021"
default-run = "server"

View File

@ -605,7 +605,7 @@ fn compute_offset_limit(
}
}
#[derive(Debug, Default)]
#[derive(Debug)]
pub struct Query {
pub unread_only: bool,
pub tags: Vec<String>,

View File

@ -57,7 +57,7 @@ impl TantivyConnection {
);
let start_time = std::time::Instant::now();
let (searcher, _query) = self.searcher_and_query(&Query::default())?;
let (searcher, _query) = self.searcher_and_query("")?;
let docs = searcher.search(&AllQuery, &DocSetCollector)?;
let uid = self.get_index()?.schema().get_field("uid")?;
let t_uids: Vec<_> = docs
@ -187,7 +187,7 @@ impl TantivyConnection {
}
fn searcher_and_query(
&self,
query: &Query,
term: &str,
) -> Result<(Searcher, Box<dyn query::Query>), ServerError> {
let index = self.get_index()?;
let reader = index.reader()?;
@ -197,41 +197,20 @@ impl TantivyConnection {
let summary = schema.get_field("summary")?;
let query_parser = QueryParser::for_index(&index, vec![title, summary]);
// Tantivy uses '*' to match all docs, not empty string
let term = &query.remainder.join(" ");
let term = if term.is_empty() { "*" } else { term };
info!("query_parser('{term}')");
let tantivy_query = query_parser.parse_query(&term)?;
let tag = self.get_index()?.schema().get_field("tag")?;
let is_read = self.get_index()?.schema().get_field("is_read")?;
let mut terms = vec![(Occur::Must, tantivy_query)];
for t in &query.tags {
let facet = Facet::from(&format!("/{t}"));
let facet_term = Term::from_facet(tag, &facet);
let facet_term_query = Box::new(TermQuery::new(facet_term, IndexRecordOption::Basic));
terms.push((Occur::Must, facet_term_query));
}
if query.unread_only {
info!("searching for unread only");
let term = Term::from_field_bool(is_read, false);
terms.push((
Occur::Must,
Box::new(TermQuery::new(term, IndexRecordOption::Basic)),
));
}
let search_query = BooleanQuery::new(terms);
Ok((searcher, Box::new(search_query)))
let query = query_parser.parse_query(&term)?;
Ok((searcher, query))
}
pub async fn count(&self, query: &Query) -> Result<usize, ServerError> {
if !is_tantivy_query(query) {
return Ok(0);
}
info!("tantivy::count {query:?}");
use tantivy::collector::Count;
let term = query.remainder.join(" ");
let (searcher, query) = self.searcher_and_query(&query)?;
let (searcher, query) = self.searcher_and_query(&term)?;
Ok(searcher.search(&query, &Count)?)
}
pub async fn search(
@ -254,8 +233,27 @@ impl TantivyConnection {
limit = limit + 1;
}
let (searcher, search_query) = self.searcher_and_query(&query)?;
info!("Tantivy::search(query '{query:?}', off {offset}, lim {limit}, search_query {search_query:?})");
let term = query.remainder.join(" ");
let (searcher, tantivy_query) = self.searcher_and_query(&term)?;
let tag = self.get_index()?.schema().get_field("tag")?;
let is_read = self.get_index()?.schema().get_field("is_read")?;
let mut terms = vec![(Occur::Must, tantivy_query)];
for t in &query.tags {
let facet = Facet::from(&format!("/{t}"));
let facet_term = Term::from_facet(tag, &facet);
let facet_term_query = Box::new(TermQuery::new(facet_term, IndexRecordOption::Basic));
terms.push((Occur::Must, facet_term_query));
}
if query.unread_only {
info!("searching for unread only");
let term = Term::from_field_bool(is_read, false);
terms.push((
Occur::Must,
Box::new(TermQuery::new(term, IndexRecordOption::Basic)),
));
}
let search_query = BooleanQuery::new(terms);
info!("Tantivy::search(term '{term}', off {offset}, lim {limit}, search_query {search_query:?})");
let top_docs = searcher.search(
&search_query,
&TopDocs::with_limit(limit as usize)

View File

@ -1,6 +1,6 @@
[package]
name = "shared"
version = "0.0.52"
version = "0.0.51"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -1,5 +1,5 @@
[package]
version = "0.0.52"
version = "0.0.51"
name = "letterbox"
repository = "https://github.com/seed-rs/seed-quickstart"
authors = ["Bill Thiede <git@xinu.tv>"]