Skip to content

Commit

Permalink
Finish filter-only feature by fixing empty excerpts
Browse files Browse the repository at this point in the history
  • Loading branch information
bglw committed Oct 26, 2022
1 parent 3fec9ad commit 0636663
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
22 changes: 22 additions & 0 deletions pagefind/features/filtering.feature
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,28 @@ Feature: Filtering
Then There should be no logs
Then The selector "[data-results]" should contain "/cheeka/, /theodore/"

Scenario: Filtering without search term returns an unprocessed excerpt
When I evaluate:
"""
async function() {
let pagefind = await import("/_pagefind/pagefind.js");
// Run a search so that some index words are loaded
let unused = await pagefind.search("cat");
let search = await pagefind.search(null, {
filters: {
color: ["Black", "White"]
}
});
let data = await Promise.all(search.results.map(result => result.data()));
document.querySelector('[data-results]').innerText = data.map(d => d.excerpt).join(', ');
}
"""
Then There should be no logs
Then The selector "[data-results]" should contain "Black White Cat."

@skip
# Currently only an AND filtering is supported. Need to restructure to support boolean logic
Scenario: Filtering to multiple values
Expand Down
2 changes: 1 addition & 1 deletion pagefind_web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub fn add_synthetic_filter(ptr: *mut SearchIndex, filter: &str) -> *mut SearchI
#[wasm_bindgen]
pub fn request_indexes(ptr: *mut SearchIndex, query: &str) -> String {
let indexes = try_request_indexes(ptr, query, false);
if indexes.is_empty() {
if indexes.is_empty() && !query.trim().is_empty() {
debug!({
"No index chunks found with strict boundaries. Loading all possible extension chunks."
});
Expand Down
3 changes: 3 additions & 0 deletions pagefind_web/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ impl SearchIndex {
}

fn stems_from_term(term: &str) -> Vec<Cow<str>> {
if term.trim().is_empty() {
return vec![];
}
let stemmer = Stemmer::try_create_default();
term.split(' ')
.map(|word| match &stemmer {
Expand Down

0 comments on commit 0636663

Please sign in to comment.