Skip to content

Commit

Permalink
Planet tuning, switch to planet server
Browse files Browse the repository at this point in the history
  • Loading branch information
ellenhp committed Feb 11, 2024
1 parent 0b1ca01 commit feb0384
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
2 changes: 1 addition & 1 deletion airmail/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde_json::Value;
use tantivy::{
collector::TopDocs,
directory::MmapDirectory,
query::{BooleanQuery, DisjunctionMaxQuery, FuzzyTermQuery, Query},
query::{BooleanQuery, FuzzyTermQuery, Query},
schema::{FacetOptions, Schema, TextFieldIndexing, TextOptions, INDEXED, STORED, TEXT},
tokenizer::{LowerCaser, RawTokenizer, TextAnalyzer},
Term,
Expand Down
58 changes: 30 additions & 28 deletions airmail_service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,39 +36,41 @@ async fn search(

let scenarios = parsed.scenarios();
let start = std::time::Instant::now();
let mut results: Vec<(AirmailPoi, f32, QueryScenario)> = scenarios
.iter()
.take(10)
.filter_map(|scenario| {
let results = index.search(scenario).unwrap();
if results.is_empty() {
None
} else {
Some(
results
.iter()
.map(|(poi, score)| {
(
poi.clone(),
*score * scenario.penalty_mult(),
scenario.clone(),
)
})
.collect::<Vec<_>>(),
)
}
})
.take(3)
.flatten()
.collect();
let mut all_results: Vec<(AirmailPoi, f32, QueryScenario)> = vec![];
for scenario in scenarios.iter().take(3) {
if all_results.len() > 20 {
break;
}
let results = index.search(scenario).unwrap();
if results.is_empty() {
continue;
} else {
all_results.extend(
results
.iter()
.map(|(poi, score)| {
(
poi.clone(),
*score * scenario.penalty_mult(),
scenario.clone(),
)
})
.collect::<Vec<_>>(),
);
}
}

results.sort_by(|(_, a, _), (_, b, _)| b.partial_cmp(a).unwrap());
all_results.sort_by(|(_, a, _), (_, b, _)| b.partial_cmp(a).unwrap());

println!("{} results found in {:?}", results.len(), start.elapsed());
println!(
"{} results found in {:?}",
all_results.len(),
start.elapsed()
);

let mut response = Response {
metadata: HashMap::new(),
features: results
features: all_results
.clone()
.iter()
.map(|(results, _, _)| results.clone())
Expand Down
3 changes: 1 addition & 2 deletions airmail_site/src/components/Demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ async function fetchSearchResults(query) {
pins.value = [];
return;
}
const url = `https://api.airmail.rs/search?q=${query}`;
const url = `https://api2.airmail.rs/search?q=${query}`;
const response = await fetch(url);
const data = await response.json();
console.log(data);
var newPins = data.features.map((poi) => {
return {
"type": "Feature",
Expand Down

0 comments on commit feb0384

Please sign in to comment.