Skip to content

Commit

Permalink
Fixed support for advanced FTS syntax, closes #13
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Sep 3, 2020
1 parent ed1d0fc commit cbb2491
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions dogsheep_beta/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ async def get_count_and_facets(datasette, database_name, request):
}
if q:
args["_search"] = q
args["_searchmode"] = "raw"
for column in FILTER_COLS:
if column in request.args:
args[column] = request.args[column]
Expand Down
2 changes: 1 addition & 1 deletion dogsheep_beta/templates/beta.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ <h2>{{ facet.name }}</h2>

<section class="results">
{% for result in results %}
<div class="result">
<div class="result" data-table-key="{{ result.table }}:{{ result.key }}">
{{ result.output|safe }}
</div>
{% endfor %}
Expand Down
25 changes: 25 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import textwrap
import sqlite_utils
import pytest
import urllib
import httpx


Expand Down Expand Up @@ -90,6 +91,30 @@ async def test_search(ds):
]


@pytest.mark.asyncio
@pytest.mark.parametrize(
"q,expected",
(
(
"things NOT email",
[
"github.db/commits:a5b39c5049b28997528bb0eca52730ab6febabeaba54cfcba0ab5d70e7207523"
],
),
),
)
async def test_advanced_search(ds, q, expected):
async with httpx.AsyncClient(app=ds.app()) as client:
response = await client.get(
"http://localhost/-/beta?" + urllib.parse.urlencode({"q": q})
)
soup = Soup(response.text, "html5lib")
results = [el["data-table-key"] for el in soup.select("[data-table-key]")]
assert results == expected
# Check that facets exist on the page
assert len(soup.select(".facet li")), "Could not see any facet results"


@pytest.mark.asyncio
async def test_fixture(ds):
async with httpx.AsyncClient(app=ds.app()) as client:
Expand Down

0 comments on commit cbb2491

Please sign in to comment.