Skip to content

Commit

Permalink
Initial support for filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
bglw committed May 26, 2022
1 parent 630d88c commit 587381d
Show file tree
Hide file tree
Showing 25 changed files with 627 additions and 97 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,18 @@ jobs:
ls -lh ./vendor/
cargo package --allow-dirty
- name: Test Web
working-directory: ./pagefind_web
run: cargo test

- name: Test Lib
working-directory: ./pagefind
run: cargo test --lib

- name: Test CLI
working-directory: ./pagefind
run: TEST_BINARY=../target/release/pagefind cargo test --release --test cucumber -- -c 16 --tags "not @skip"

- name: Build
working-directory: ./pagefind
run: RELEASE_VERSION=${GITHUB_REF#refs/tags/} cargo build --release --target ${{ matrix.target }}
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ jobs:
working-directory: ./pagefind_web
run: cargo test

- name: Test Lib
working-directory: ./pagefind
run: cargo test --lib

- name: Test CLI
working-directory: ./pagefind
run: TEST_BINARY=../target/release/pagefind cargo test --release --test cucumber -- -c 16 --tags "not @skip"
1 change: 1 addition & 0 deletions pagefind/features/base.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ Feature: Base Tests
document.querySelector('[data-url]').innerText = data.url;
}
"""
Then There should be no logs
Then The selector "[data-url]" should contain "/cat/"
2 changes: 2 additions & 0 deletions pagefind/features/build_options.feature
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Feature: Build Options
document.querySelector('[data-url]').innerText = data.url;
}
"""
Then There should be no logs
Then The selector "[data-url]" should contain "/cat/"

Scenario: Output path can be configured
Expand Down Expand Up @@ -69,6 +70,7 @@ Feature: Build Options
document.querySelector('[data-url]').innerText = data.url;
}
"""
Then There should be no logs
Then The selector "[data-url]" should contain "/cat/"

@skip
Expand Down
3 changes: 3 additions & 0 deletions pagefind/features/exact_phrase.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Feature: Exact Phrase Matching
document.querySelector('[data-result]').innerText = data.url;
}
"""
Then There should be no logs
Then The selector "[data-count]" should contain "1 result(s)"
Then The selector "[data-result]" should contain "/cat/"

Expand Down Expand Up @@ -69,6 +70,7 @@ Feature: Exact Phrase Matching
document.querySelector('[data-result]').innerText = data.url;
}
"""
Then There should be no logs
Then The selector "[data-count]" should contain "1 result(s)"
Then The selector "[data-result]" should contain "/cattwo/"

Expand Down Expand Up @@ -102,6 +104,7 @@ Feature: Exact Phrase Matching
document.querySelector('[data-result]').innerText = data.map(d => d.url).join(', ');
}
"""
Then There should be no logs
Then The selector "[data-count]" should contain "2 result(s)"
Then The selector "[data-result]" should contain "/cat/, /dog/"

2 changes: 2 additions & 0 deletions pagefind/features/exclusions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Feature: Exclusions
document.querySelector('[data-search-two]').innerText = `${searchtwo.length} result(s)`;
}
"""
Then There should be no logs
Then The selector "[data-search-one]" should contain "Hello World, from Pagefind. Huzzah!"
Then The selector "[data-search-two]" should contain "0 result(s)"

Expand Down Expand Up @@ -75,5 +76,6 @@ Feature: Exclusions
document.querySelector('[data-search-two]').innerText = `${searchtwo.length} result(s)`;
}
"""
Then There should be no logs
Then The selector "[data-search-one]" should contain "Hello World, from Pagefind. Hooray!"
Then The selector "[data-search-two]" should contain "0 result(s)"
76 changes: 69 additions & 7 deletions pagefind/features/filtering.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@skip
Feature: Filtering
Background:
Given I have a "public/index.html" file with the content:
Expand Down Expand Up @@ -44,16 +43,17 @@ Feature: Filtering
document.querySelector('[data-results]').innerText = data.map(d => d.url).sort().join(', ');
}
"""
Then There should be no logs
Then The selector "[data-results]" should contain "/ali/, /cheeka/, /theodore/"

Scenario: Filtering on tagged elements
When I evaluate:
"""js
"""
async function() {
let pagefind = await import("/_pagefind/pagefind.js");
let results = await pagefind.search("Cat", {
filter: {
filters: {
color: "Orange"
}
});
Expand All @@ -62,16 +62,17 @@ Feature: Filtering
document.querySelector('[data-results]').innerText = data.map(d => d.url).sort().join(', ');
}
"""
Then There should be no logs
Then The selector "[data-results]" should contain "/theodore/"

Scenario: Filtering on tagged values
When I evaluate:
"""js
"""
async function() {
let pagefind = await import("/_pagefind/pagefind.js");
let results = await pagefind.search("Cat", {
filter: {
filters: {
color: "Tabby"
}
});
Expand All @@ -80,16 +81,17 @@ Feature: Filtering
document.querySelector('[data-results]').innerText = data.map(d => d.url).sort().join(', ');
}
"""
Then There should be no logs
Then The selector "[data-results]" should contain "/ali/"

Scenario: Filtering returns multiple results
When I evaluate:
"""js
"""
async function() {
let pagefind = await import("/_pagefind/pagefind.js");
let results = await pagefind.search("Cat", {
filter: {
filters: {
color: "White"
}
});
Expand All @@ -98,4 +100,64 @@ Feature: Filtering
document.querySelector('[data-results]').innerText = data.map(d => d.url).sort().join(', ');
}
"""
Then There should be no logs
Then The selector "[data-results]" should contain "/cheeka/, /theodore/"

@skip
# Currently only an AND filtering is supported. Need to restructure to support boolean logic
Scenario: Filtering to multiple values
When I evaluate:
"""
async function() {
let pagefind = await import("/_pagefind/pagefind.js");
let results = await pagefind.search("Cat", {
filters: {
color: ["Tabby", "Orange"]
}
});
let data = await Promise.all(results.map(result => result.data()));
document.querySelector('[data-results]').innerText = data.map(d => d.url).sort().join(', ');
}
"""
Then There should be no logs
Then The selector "[data-results]" should contain "/ali/, /theodore/"

@skip
Scenario: Non-existent filters return no results
When I evaluate:
"""
async function() {
let pagefind = await import("/_pagefind/pagefind.js");
let results = await pagefind.search("Cat", {
filters: {
name: "Ali"
}
});
document.querySelector('[data-results]').innerText = results.length;
}
"""
Then There should be no logs
Then The selector "[data-results]" should contain "0"

@skip
Scenario: Non-existent values return no results
When I evaluate:
"""
async function() {
let pagefind = await import("/_pagefind/pagefind.js");
let results = await pagefind.search("Cat", {
filters: {
color: "Green"
}
});
document.querySelector('[data-results]').innerText = results.length;
}
"""
Then There should be no logs
Then The selector "[data-results]" should contain "0"
22 changes: 20 additions & 2 deletions pagefind/features/fragments.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ Feature: Fragments
Given I have a "public/cat/index.html" file with the content:
"""
<body>
<h1>Cat Post.</h1>
<h1 data-pagefind-filter="title">
Cat Post.
</h1>
<span data-pagefind-ignore data-pagefind-filter="animal">cats</span>
<p>A post about the 'felines'</p>
<p>This post has some <span>gnarly<span> things to test the fragment formatting.</p>
</body>
Expand All @@ -31,6 +34,7 @@ Feature: Fragments
document.querySelector('[data-result]').innerText = data.title;
}
"""
Then There should be no logs
Then The selector "[data-result]" should contain "Cat Post."

Scenario: Search results return nicely formatted content
Expand All @@ -45,6 +49,7 @@ Feature: Fragments
document.querySelector('[data-result]').innerText = data.content;
}
"""
Then There should be no logs
Then The selector "[data-result]" should contain "Cat Post. A post about the 'felines'. This post has some gnarly things to test the fragment formatting."

Scenario: Search results return highlighted search exerpt
Expand All @@ -59,11 +64,24 @@ Feature: Fragments
document.querySelector('[data-result]').innerText = data.excerpt;
}
"""
Then There should be no logs
# NB: The HTML encoding below is a test artifact
Then The selector "[data-result]" should contain "Cat Post. A post about the &lt;mark&gt;'felines'.&lt;/mark&gt; This post has some gnarly things to test the fragment formatting."

@skip
Scenario: Search results return tagged filters
When I evaluate:
"""
async function() {
let pagefind = await import("/_pagefind/pagefind.js");
let results = await pagefind.search("cat");
let data = await results[0].data();
document.querySelector('[data-result]').innerText = Object.entries(data.filters).map(([f, v]) => `${f}: ${v}`).sort().join(', ');
}
"""
Then There should be no logs
Then The selector "[data-result]" should contain "animal: cats, title: Cat Post."

@skip
Scenario: Search results return tagged metadata
Expand Down
1 change: 1 addition & 0 deletions pagefind/features/partial_matching.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ Feature: Partial Matching
document.querySelector('[data-url]').innerText = data.url;
}
"""
Then There should be no logs
Then The selector "[data-url]" should contain "/cat/"

3 changes: 3 additions & 0 deletions pagefind/features/scoring.feature
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Feature: Result Scoring
document.querySelector('[data-result]').innerText = data.map(d => d.url).join(', ');
}
"""
Then There should be no logs
Then The selector "[data-count]" should contain "2 result(s)"
Then The selector "[data-result]" should contain "/dog/, /cat/"

Expand All @@ -69,6 +70,7 @@ Feature: Result Scoring
document.querySelector('[data-result]').innerText = data.map(d => d.url).join(', ');
}
"""
Then There should be no logs
Then The selector "[data-count]" should contain "2 result(s)"
Then The selector "[data-result]" should contain "/dog/, /cat/"
When I evaluate:
Expand All @@ -83,5 +85,6 @@ Feature: Result Scoring
document.querySelector('[data-result]').innerText = data.map(d => d.url).join(', ');
}
"""
Then There should be no logs
Then The selector "[data-count]" should contain "2 result(s)"
Then The selector "[data-result]" should contain "/cat/, /dog/"
2 changes: 2 additions & 0 deletions pagefind/features/stemming.feature
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Feature: Word Stemming
document.querySelector('[data-result]').innerText = data.url;
}
"""
Then There should be no logs
Then The selector "[data-result]" should contain "/cat/"

Scenario: Search is case independent
Expand All @@ -55,5 +56,6 @@ Feature: Word Stemming
document.querySelector('[data-result]').innerText = data.url;
}
"""
Then There should be no logs
Then The selector "[data-result]" should contain "/cat/"

Loading

0 comments on commit 587381d

Please sign in to comment.