Skip to content

Commit

Permalink
remove duplicate search result
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub committed Nov 11, 2023
1 parent 55e160b commit 01675aa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
4 changes: 1 addition & 3 deletions src/controller/inn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,9 +723,7 @@ pub(crate) async fn edit_post_post(
claim.update_last_write(&DB)?;

if inn.inn_type.as_str() != "Private" {
let is_update: &[u8] = if old_pid == 0 { &[] } else { &[0] };
DB.open_tree("tan")?
.insert(format!("post{}", pid), is_update)?;
DB.open_tree("tan")?.insert(format!("post{}", pid), &[])?;
}

let target = format!("/post/{iid}/{pid}");
Expand Down
2 changes: 1 addition & 1 deletion src/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//! | "user_uploads" | `uid#img_id` | `image_hash.ext` |
//! | default | "imgs_count" | N |
//! | "home_pages" | `uid` | `u8` |
//! | "tan" | `ctype#id` | `&[]`or &[0] |
//! | "tan" | `ctype#id` | `&[]` |
//!
//! ### notification
//! | tree | key | value |
Expand Down
13 changes: 9 additions & 4 deletions src/controller/tantivy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub(crate) async fn search(
}
};

let mut out_searchs = Vec::with_capacity(20);
let mut ids = HashSet::with_capacity(20);
if !search.is_empty() {
let (query, err) = SEARCHER.query_parser.parse_query_lenient(&query);
if !err.is_empty() {
Expand All @@ -99,9 +99,14 @@ pub(crate) async fn search(
for (_score, doc_address) in top_docs {
let doc = searcher.doc(doc_address)?;
let id = doc.get_first(FIELDS.id).unwrap().as_text().unwrap();
if let Some(out) = OutSearch::get(id, &DB) {
out_searchs.push(out);
}
ids.insert(id.to_owned());
}
}

let mut out_searchs = Vec::with_capacity(20);
for id in ids {
if let Some(out) = OutSearch::get(&id, &DB) {
out_searchs.push(out);
}
}

Expand Down
10 changes: 2 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,12 @@ async fn main() -> Result<(), AppError> {
let mut subscriber = DB.open_tree("tan").unwrap().watch_prefix(vec![]);
while let Some(event) = (&mut subscriber).await {
let (k, op_type) = match event {
sled::Event::Insert { key, value } => {
if value.len() == 1 {
(key, "update")
} else {
(key, "add")
}
}
sled::Event::Insert { key, value: _ } => (key, "add"),
sled::Event::Remove { key } => (key, "delete"),
};
let id = String::from_utf8_lossy(&k);

if op_type == "update" || op_type == "add" {
if op_type == "add" {
tan.add_doc(&id, &DB).unwrap();
}

Expand Down

0 comments on commit 01675aa

Please sign in to comment.