Transform `tantivy_addresses_to_ids!` into a method
This is the easy one. I'm not looking forward to tackling the other two macros in the `basic_search` code...
- Id
- 037cbb36f7924dba6e4f180ccdb1abc6ea2534a1
- Author
- Caio
- Commit time
- 2019-12-06T12:21:01+01:00
Modified crates/cantine/src/bin/query.rs
};
use tique::{
queryparser::QueryParser,
- top_collector::{ordered_by_u64_fast_field, ConditionalTopCollector},
+ top_collector::{ordered_by_u64_fast_field, ConditionalTopCollector, SearchMarker},
};
/// Queries data generated via `load`
}
}
+ fn addresses_to_ids<T>(
+ &self,
+ searcher: &Searcher,
+ addresses: &[SearchMarker<T>],
+ ) -> Result<Vec<u64>> {
+ let mut items = Vec::with_capacity(addresses.len());
+
+ for addr in addresses.iter() {
+ let doc = searcher.doc(addr.doc)?;
+ if let Some(&Value::U64(id)) = doc.get_first(self.fields.id) {
+ items.push(id);
+ } else {
+ panic!("Found document without a stored id");
+ }
+ }
+
+ Ok(items)
+ }
+
fn basic_search(
&self,
searcher: &Searcher,
sort: Sort,
after: SearchCursor,
) -> Result<(usize, Vec<u64>, Option<SearchCursor>)> {
- macro_rules! tantivy_addresses_to_ids {
- ($topdocs:expr) => {{
- let mut items = Vec::with_capacity($topdocs.len());
-
- for item in $topdocs.iter() {
- let doc = searcher.doc(item.doc)?;
- if let Some(&Value::U64(id)) = doc.get_first(self.fields.id) {
- items.push(id);
- } else {
- panic!("Found document without a stored id");
- }
- }
-
- items
- }};
- }
-
macro_rules! condition_from_score {
($score:expr) => {{
let after_score = $score;
ordered_by_u64_fast_field(self.fields.features.$field, limit, condition);
let result = searcher.search(interpreted_query, &top_collector)?;
- let items = tantivy_addresses_to_ids!(result.items);
+ let items = self.addresses_to_ids(&searcher, &result.items)?;
let num_items = items.len();
let cursor = if result.visited.saturating_sub(num_items) > 0 {
let top_collector = ConditionalTopCollector::with_limit(limit, condition);
let result = searcher.search(interpreted_query, &top_collector)?;
- let items = tantivy_addresses_to_ids!(result.items);
+ let items = self.addresses_to_ids(&searcher, &result.items)?;
let num_items = items.len();
let cursor = if result.visited.saturating_sub(num_items) > 0 {