Skip to content

Commit 66f8032

Browse files
committed
added exact and then starts with
1 parent 9c2f176 commit 66f8032

File tree

1 file changed

+96
-46
lines changed

1 file changed

+96
-46
lines changed

src/sauce/home.rs

Lines changed: 96 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -311,52 +311,102 @@ pub fn home() -> Html {
311311
})
312312
};
313313

314-
let filtered_data: Vec<TableLine> = mock_data.data
315-
.iter()
316-
.enumerate()
317-
.filter(|(_, entry)| {
318-
let element = &entry.element;
319-
let nucleons = &entry.nucleons;
320-
let reaction = &entry.reaction;
321-
let mt = &entry.mt;
322-
let library = &entry.library;
323-
324-
let element_match = match element_search {
325-
Some(ref term) => element.to_lowercase() == term.to_lowercase(),
326-
None => true,
327-
};
328-
let nucleons_match = match nucleons_search {
329-
Some(ref term) => nucleons.to_string() == *term,
330-
None => true,
331-
};
332-
let reaction_match = match reaction_search {
333-
Some(ref term) => reaction.to_lowercase() == term.to_lowercase(),
334-
None => true,
335-
};
336-
let mt_match = match mt_search {
337-
Some(ref term) => mt.to_string() == *term,
338-
None => true,
339-
};
340-
let library_match = match library_search {
341-
Some(ref term) => library.to_lowercase() == term.to_lowercase(),
342-
None => true,
343-
};
344-
345-
element_match && nucleons_match && reaction_match && mt_match && library_match
346-
})
347-
.map(|(index, entry)| TableLine {
348-
original_index: index,
349-
id: entry.id,
350-
element: entry.element.clone(),
351-
nucleons: entry.nucleons.clone(),
352-
reaction: entry.reaction.clone(),
353-
mt: entry.mt.clone(),
354-
library: entry.library.clone(),
355-
temperature: entry.temperature.clone(),
356-
checked: selected_indexes.current().contains(&index),
357-
sum_callback: callback_sum.clone(),
358-
})
359-
.collect();
314+
let filtered_data: Vec<TableLine> = {
315+
// First pass: check for exact matches across all entries
316+
let has_element_exact = match element_search {
317+
Some(ref term) => {
318+
let term_lower = term.to_lowercase();
319+
mock_data.data.iter().any(|entry| entry.element.to_lowercase() == term_lower)
320+
}
321+
None => true,
322+
};
323+
let has_reaction_exact = match reaction_search {
324+
Some(ref term) => {
325+
let term_lower = term.to_lowercase();
326+
mock_data.data.iter().any(|entry| entry.reaction.to_lowercase() == term_lower)
327+
}
328+
None => true,
329+
};
330+
let has_library_exact = match library_search {
331+
Some(ref term) => {
332+
let term_lower = term.to_lowercase();
333+
mock_data.data.iter().any(|entry| entry.library.to_lowercase() == term_lower)
334+
}
335+
None => true,
336+
};
337+
338+
// Second pass: filter based on match criteria
339+
mock_data.data
340+
.iter()
341+
.enumerate()
342+
.filter(|(_, entry)| {
343+
let element = &entry.element;
344+
let nucleons = &entry.nucleons;
345+
let reaction = &entry.reaction;
346+
let mt = &entry.mt;
347+
let library = &entry.library;
348+
349+
let element_match = match element_search {
350+
Some(ref term) => {
351+
let term_lower = term.to_lowercase();
352+
let element_lower = element.to_lowercase();
353+
if has_element_exact {
354+
element_lower == term_lower
355+
} else {
356+
element_lower.starts_with(&term_lower)
357+
}
358+
}
359+
None => true,
360+
};
361+
let nucleons_match = match nucleons_search {
362+
Some(ref term) => nucleons.to_string() == *term,
363+
None => true,
364+
};
365+
let reaction_match = match reaction_search {
366+
Some(ref term) => {
367+
let term_lower = term.to_lowercase();
368+
let reaction_lower = reaction.to_lowercase();
369+
if has_reaction_exact {
370+
reaction_lower == term_lower
371+
} else {
372+
reaction_lower.starts_with(&term_lower)
373+
}
374+
}
375+
None => true,
376+
};
377+
let mt_match = match mt_search {
378+
Some(ref term) => mt.to_string() == *term,
379+
None => true,
380+
};
381+
let library_match = match library_search {
382+
Some(ref term) => {
383+
let term_lower = term.to_lowercase();
384+
let library_lower = library.to_lowercase();
385+
if has_library_exact {
386+
library_lower == term_lower
387+
} else {
388+
library_lower.starts_with(&term_lower)
389+
}
390+
}
391+
None => true,
392+
};
393+
394+
element_match && nucleons_match && reaction_match && mt_match && library_match
395+
})
396+
.map(|(index, entry)| TableLine {
397+
original_index: index,
398+
id: entry.id,
399+
element: entry.element.clone(),
400+
nucleons: entry.nucleons.clone(),
401+
reaction: entry.reaction.clone(),
402+
mt: entry.mt.clone(),
403+
library: entry.library.clone(),
404+
temperature: entry.temperature.clone(),
405+
checked: selected_indexes.current().contains(&index),
406+
sum_callback: callback_sum.clone(),
407+
})
408+
.collect()
409+
};
360410

361411
let limit = 10;
362412
let current_page = if filtered_data.is_empty() {

0 commit comments

Comments
 (0)