Implement search
simonw opened this issue · comments
Simon Willison commented
Prototype:
- https://www.niche-museums.com/browse?sql=select+museums.id%2C+museums.name%2C+museums_fts.rank+from+museums+join+museums_fts+on+museums.id+%3D+museums_fts.rowid+where+museums_fts+match+%3Asearch+order+by+museums_fts.rank&search=space
- https://www.niche-museums.com/browse?sql=select%0D%0A++museums.id%2C%0D%0A++museums.name%2C%0D%0A++museums_fts.rank%0D%0Afrom%0D%0A++museums%0D%0A++join+museums_fts+on+museums.id+%3D+museums_fts.rowid%0D%0Awhere%0D%0A++museums_fts+match+%3Asearch%0D%0Aorder+by%0D%0A++museums_fts.rank&search=san+francisco
Simon Willison commented
Maybe something like this:
https://codepen.io/simonwillison/pen/wvBwjNy
<section class="hero is-dark is-bold">
<div class="hero-body">
<div class="container">
<h1 class="title">
Niche Museums
</h1>
<h2 class="subtitle">
Find tiny museums <span class="is-hidden-mobile">near you</span>
</h2>
<div class="buttons" style="display: block;" id="buttons">
<button class="button is-link">Use my location</button>
</div>
<div class="field has-addons">
<div class="control">
<input class="input is-small" type="text" placeholder="Search">
</div>
<div class="control">
<input type="submit" class="button is-small" value="🔍"> </div>
</div>
</div>
</div>
</section>
Simon Willison commented
Slightly better query: does't throw an error on empty input:
select
museums_fts.rank,
museums.*
from
museums
join museums_fts on museums.id = museums_fts.rowid
where
museums_fts match case
:q
when '' then '*'
else :q
end
order by
museums_fts.rank
Simon Willison commented