37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
import re
|
|
|
|
with open("server/src/search.rs", "r", encoding="utf-8") as f:
|
|
content = f.read()
|
|
|
|
# Remove writer.commit() from index_*
|
|
content = content.replace(" writer.commit()?;\n", "")
|
|
|
|
# Add pub fn commit
|
|
commit_code = """
|
|
pub fn commit(&self) -> tantivy::Result<()> {
|
|
let mut writer = self.writer.lock().unwrap();
|
|
writer.commit()?;
|
|
Ok(())
|
|
}
|
|
"""
|
|
|
|
content = content.replace(" pub fn search(&self, query_str: &str, limit: usize) -> tantivy::Result<Vec<SearchResult>> {", commit_code + "\n pub fn search(&self, query_str: &str, limit: usize) -> tantivy::Result<Vec<SearchResult>> {")
|
|
|
|
with open("server/src/search.rs", "w", encoding="utf-8") as f:
|
|
f.write(content)
|
|
|
|
with open("server/src/state.rs", "r", encoding="utf-8") as f:
|
|
state_content = f.read()
|
|
|
|
# Call new_idx.commit() in rebuild_index before locking the main rwlock
|
|
state_content = state_content.replace(""" if let Ok(mut w) = self.search_index.write() {
|
|
*w = new_idx;
|
|
}""", """ let _ = new_idx.commit();
|
|
if let Ok(mut w) = self.search_index.write() {
|
|
*w = new_idx;
|
|
}""")
|
|
|
|
with open("server/src/state.rs", "w", encoding="utf-8") as f:
|
|
f.write(state_content)
|
|
|