home / content / repos

repos: 197431109

This data as json

id node_id name full_name private owner html_url description fork created_at updated_at pushed_at homepage size stargazers_count watchers_count language has_issues has_projects has_downloads has_wiki has_pages forks_count archived disabled open_issues_count license topics forks open_issues watchers default_branch permissions temp_clone_token organization network_count subscribers_count readme readme_html allow_forking visibility is_template template_repository web_commit_signoff_required has_discussions
197431109 MDEwOlJlcG9zaXRvcnkxOTc0MzExMDk= dogsheep-beta dogsheep/dogsheep-beta 0 53015001 https://github.com/dogsheep/dogsheep-beta Build a search index across content from multiple SQLite database tables and run faceted searches against it using Datasette 0 2019-07-17T17:07:26Z 2021-06-13T14:39:01Z 2021-06-13T14:38:59Z https://dogsheep.github.io/ 61 78 78 Python 1 0 1 0 0 0 0 0 11   ["search", "datasette", "datasette-plugin", "dogsheep", "datasette-io", "datasette-tool"] 0 11 78 main {"admin": false, "push": false, "pull": false}   53015001 0 4 # dogsheep-beta [![PyPI](https://img.shields.io/pypi/v/dogsheep-beta.svg)](https://pypi.org/project/dogsheep-beta/) [![Changelog](https://img.shields.io/github/v/release/dogsheep/beta?include_prereleases&label=changelog)](https://github.com/dogsheep/beta/releases) [![Tests](https://github.com/dogsheep/beta/workflows/Test/badge.svg)](https://github.com/dogsheep/beta/actions?query=workflow%3ATest) [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/dogsheep/beta/blob/main/LICENSE) Build a search index across content from multiple SQLite database tables and run faceted searches against it using Datasette ## Example A live example of this plugin is running at https://datasette.io/-/beta - configured using [this YAML file](https://github.com/simonw/datasette.io/blob/main/templates/dogsheep-beta.yml). Read more about how this example works in [Building a search engine for datasette.io](https://simonwillison.net/2020/Dec/19/dogsheep-beta/). ## Installation Install this tool like so: $ pip install dogsheep-beta ## Usage Run the indexer using the `dogsheep-beta` command-line tool: $ dogsheep-beta index dogsheep.db config.yml The `config.yml` file contains details of the databases and document types that should be indexed: ```yaml twitter.db: tweets: sql: |- select tweets.id as key, 'Tweet by @' || users.screen_name as title, tweets.created_at as timestamp, tweets.full_text as search_1 from tweets join users on tweets.user = users.id users: sql: |- select id as key, name || ' @' || screen_name as title, created_at as timestamp, description as search_1 from users ``` This will create a `search_index` table in the `dogsheep.db` database populated by data from those SQL queries. By default the search index that this tool creates will be configured for Porter stemming. This means that searches for words like `run` will match documents containing `runs` or `running`. If you don't want to use Porter stemming, use the `--tokenize none` option: $ dogsheep-beta index dogsheep.db config.yml --tokenize none You can pass other SQLite tokenize argumenst here, see [the SQLite FTS tokenizers documentation](https://www.sqlite.org/fts5.html#tokenizers). ## Columns The columns that can be returned by our query are: - `key` - a unique (within that type) primary key - `title` - the title for the item - `timestamp` - an ISO8601 timestamp, e.g. `2020-09-02T21:00:21` - `search_1` - a larger chunk of text to be included in the search index - `category` - an integer category ID, see below - `is_public` - an integer (0 or 1, defaults to 0 if not set) specifying if this is public or not Public records are things like your public tweets, blog posts and GitHub commits. ## Categories Indexed items can be assigned a category. Categories are integers that correspond to records in the `categories` table, which defaults to containing the following: | id | name | |------|------------| | 1 | created | | 2 | saved | | 3 | received | `created` is for items that have been created by the Dogsheep instance owner. `saved` is for items that they have saved, liked or favourited. `received` is for items that have been specifically sent to them by other people - incoming emails or direct messages for example. ## Datasette plugin Run `datasette install dogsheep-beta` (or use `pip install dogsheep-beta` in the same environment as Datasette) to install the Dogsheep Beta Datasette plugin. Once installed, a custom search interface will be made available at `/-/beta`. You can use this interface to execute searches. The Datasette plugin has some configuration options. You can set these by adding the following to your `metadata.json` configuration file: ```json { "plugins": { "dogsheep-beta": { "database": "beta", "config_file": "dogsheep-beta.yml", "template_debug": true } } } ``` The configuration settings for the plugin are: - `database` - the database file that contains your search index. If the file is `beta.db` you should set `database` to `beta`. - `config_file` - the YAML file containing your Dogsheep Beta configuration. - `template_debug` - set this to `true` to enable debugging output if errors occur in your custom templates, see below. ## Custom results display Each indexed item type can define custom display HTML as part of the `config.yml` file. It can do this using a `display` key containing a fragment of Jinja template, and optionally a `display_sql` key with extra SQL to execute to fetch the data to display. Here's how to define a custom display template for a tweet: ```yaml twitter.db: tweets: sql: |- select tweets.id as key, 'Tweet by @' || users.screen_name as title, tweets.created_at as timestamp, tweets.full_text as search_1 from tweets join users on tweets.user = users.id display: |- <p>{{ title }} - tweeted at {{ timestamp }}</p> <blockquote>{{ search_1 }}</blockquote> ``` This example reuses the value that were stored in the `search_index` table when the indexing query was run. To load in extra values to display in the template, use a `display_sql` query like this: ```yaml twitter.db: tweets: sql: |- select tweets.id as key, 'Tweet by @' || users.screen_name as title, tweets.created_at as timestamp, tweets.full_text as search_1 from tweets join users on tweets.user = users.id display_sql: |- select users.screen_name, tweets.full_text, tweets.created_at from tweets join users on tweets.user = users.id where tweets.id = :key display: |- <p>{{ display.screen_name }} - tweeted at {{ display.created_at }}</p> <blockquote>{{ display.full_text }}</blockquote> ``` The `display_sql` query will be executed for every search result, passing the key value from the `search_index` table as the `:key` parameter and the user's search term as the `:q` parameter. This performs well because [many small queries are efficient in SQLite](https://www.sqlite.org/np1queryprob.html). If an error occurs while rendering one of your templates the search results page will return a 500 error. You can use the `template_debug` configuration setting described above to instead output debugging information for the search results item that experienced the error. ## Displaying maps This plugin will eventually include a number of useful shortcuts for rendering interesting content. The first available shortcut is for displaying maps. Make your custom content output something like this: ```html <div data-map-latitude="{{ display.latitude }}" data-map-longitude="{{ display.longitude }}" style="display: none; float: right; width: 250px; height: 200px; background-color: #ccc;" ></div> ``` JavaScript on the page will look for any elements with `data-map-latitude` and `data-map-longitude` and, if it finds any, will load Leaflet and convert those elements into maps centered on that location. The default zoom level will be 12, or you can set a `data-map-zoom` attribute to customize this. ## Development To set up this plugin locally, first checkout the code. Then create a new virtual environment: cd dogsheep-beta python3 -mvenv venv source venv/bin/activate Or if you are using `pipenv`: pipenv shell Now install the dependencies and tests: pip install -e '.[test]' To run the tests: pytest <div id="readme" class="md" data-path="README.md"><article class="markdown-body entry-content container-lg" itemprop="text"><h1><a id="user-content-dogsheep-beta" class="anchor" aria-hidden="true" href="#user-content-dogsheep-beta"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>dogsheep-beta</h1> <p><a href="https://pypi.org/project/dogsheep-beta/" rel="nofollow"><img src="https://camo.githubusercontent.com/f8d17c422fbd622ab366c57086226b7f90b6ab9057aa2f3b9f6844dd29bac733/68747470733a2f2f696d672e736869656c64732e696f2f707970692f762f646f6773686565702d626574612e737667" alt="PyPI" data-canonical-src="https://img.shields.io/pypi/v/dogsheep-beta.svg" style="max-width:100%;"></a> <a href="https://github.com/dogsheep/beta/releases"><img src="https://camo.githubusercontent.com/341e696d2cba7197bea24e27cc6db041753c20587a00ced21e77516d26a54730/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f646f6773686565702f626574613f696e636c7564655f70726572656c6561736573266c6162656c3d6368616e67656c6f67" alt="Changelog" data-canonical-src="https://img.shields.io/github/v/release/dogsheep/beta?include_prereleases&amp;label=changelog" style="max-width:100%;"></a> <a href="https://github.com/dogsheep/beta/actions?query=workflow%3ATest"><img src="https://github.com/dogsheep/beta/workflows/Test/badge.svg" alt="Tests" style="max-width:100%;"></a> <a href="https://github.com/dogsheep/beta/blob/main/LICENSE"><img src="https://camo.githubusercontent.com/1698104e976c681143eb0841f9675c6f802bb7aa832afc0c7a4e719b1f3cf955/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d417061636865253230322e302d626c75652e737667" alt="License" data-canonical-src="https://img.shields.io/badge/license-Apache%202.0-blue.svg" style="max-width:100%;"></a></p> <p>Build a search index across content from multiple SQLite database tables and run faceted searches against it using Datasette</p> <h2><a id="user-content-example" class="anchor" aria-hidden="true" href="#user-content-example"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Example</h2> <p>A live example of this plugin is running at <a href="https://datasette.io/-/beta" rel="nofollow">https://datasette.io/-/beta</a> - configured using <a href="https://github.com/simonw/datasette.io/blob/main/templates/dogsheep-beta.yml">this YAML file</a>.</p> <p>Read more about how this example works in <a href="https://simonwillison.net/2020/Dec/19/dogsheep-beta/" rel="nofollow">Building a search engine for datasette.io</a>.</p> <h2><a id="user-content-installation" class="anchor" aria-hidden="true" href="#user-content-installation"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Installation</h2> <p>Install this tool like so:</p> <div class="snippet-clipboard-content position-relative" data-snippet-clipboard-copy-content="$ pip install dogsheep-beta "><pre><code>$ pip install dogsheep-beta </code></pre></div> <h2><a id="user-content-usage" class="anchor" aria-hidden="true" href="#user-content-usage"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Usage</h2> <p>Run the indexer using the <code>dogsheep-beta</code> command-line tool:</p> <div class="snippet-clipboard-content position-relative" data-snippet-clipboard-copy-content="$ dogsheep-beta index dogsheep.db config.yml "><pre><code>$ dogsheep-beta index dogsheep.db config.yml </code></pre></div> <p>The <code>config.yml</code> file contains details of the databases and document types that should be indexed:</p> <div class="highlight highlight-source-yaml position-relative" data-snippet-clipboard-copy-content="twitter.db: tweets: sql: |- select tweets.id as key, 'Tweet by @' || users.screen_name as title, tweets.created_at as timestamp, tweets.full_text as search_1 from tweets join users on tweets.user = users.id users: sql: |- select id as key, name || ' @' || screen_name as title, created_at as timestamp, description as search_1 from users "><pre><span class="pl-ent">twitter.db</span>: <span class="pl-ent">tweets</span>: <span class="pl-ent">sql</span>: <span class="pl-s">|-</span> <span class="pl-s"> select</span> <span class="pl-s"> tweets.id as key,</span> <span class="pl-s"> 'Tweet by @' || users.screen_name as title,</span> <span class="pl-s"> tweets.created_at as timestamp,</span> <span class="pl-s"> tweets.full_text as search_1</span> <span class="pl-s"> from tweets join users on tweets.user = users.id</span> <span class="pl-s"></span> <span class="pl-ent">users</span>: <span class="pl-ent">sql</span>: <span class="pl-s">|-</span> <span class="pl-s"> select</span> <span class="pl-s"> id as key,</span> <span class="pl-s"> name || ' @' || screen_name as title,</span> <span class="pl-s"> created_at as timestamp,</span> <span class="pl-s"> description as search_1</span> <span class="pl-s"> from users</span></pre></div> <p>This will create a <code>search_index</code> table in the <code>dogsheep.db</code> database populated by data from those SQL queries.</p> <p>By default the search index that this tool creates will be configured for Porter stemming. This means that searches for words like <code>run</code> will match documents containing <code>runs</code> or <code>running</code>.</p> <p>If you don't want to use Porter stemming, use the <code>--tokenize none</code> option:</p> <div class="snippet-clipboard-content position-relative" data-snippet-clipboard-copy-content="$ dogsheep-beta index dogsheep.db config.yml --tokenize none "><pre><code>$ dogsheep-beta index dogsheep.db config.yml --tokenize none </code></pre></div> <p>You can pass other SQLite tokenize argumenst here, see <a href="https://www.sqlite.org/fts5.html#tokenizers" rel="nofollow">the SQLite FTS tokenizers documentation</a>.</p> <h2><a id="user-content-columns" class="anchor" aria-hidden="true" href="#user-content-columns"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Columns</h2> <p>The columns that can be returned by our query are:</p> <ul> <li><code>key</code> - a unique (within that type) primary key</li> <li><code>title</code> - the title for the item</li> <li><code>timestamp</code> - an ISO8601 timestamp, e.g. <code>2020-09-02T21:00:21</code></li> <li><code>search_1</code> - a larger chunk of text to be included in the search index</li> <li><code>category</code> - an integer category ID, see below</li> <li><code>is_public</code> - an integer (0 or 1, defaults to 0 if not set) specifying if this is public or not</li> </ul> <p>Public records are things like your public tweets, blog posts and GitHub commits.</p> <h2><a id="user-content-categories" class="anchor" aria-hidden="true" href="#user-content-categories"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Categories</h2> <p>Indexed items can be assigned a category. Categories are integers that correspond to records in the <code>categories</code> table, which defaults to containing the following:</p> <table> <thead> <tr> <th>id</th> <th>name</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>created</td> </tr> <tr> <td>2</td> <td>saved</td> </tr> <tr> <td>3</td> <td>received</td> </tr> </tbody> </table> <p><code>created</code> is for items that have been created by the Dogsheep instance owner.</p> <p><code>saved</code> is for items that they have saved, liked or favourited.</p> <p><code>received</code> is for items that have been specifically sent to them by other people - incoming emails or direct messages for example.</p> <h2><a id="user-content-datasette-plugin" class="anchor" aria-hidden="true" href="#user-content-datasette-plugin"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Datasette plugin</h2> <p>Run <code>datasette install dogsheep-beta</code> (or use <code>pip install dogsheep-beta</code> in the same environment as Datasette) to install the Dogsheep Beta Datasette plugin.</p> <p>Once installed, a custom search interface will be made available at <code>/-/beta</code>. You can use this interface to execute searches.</p> <p>The Datasette plugin has some configuration options. You can set these by adding the following to your <code>metadata.json</code> configuration file:</p> <div class="highlight highlight-source-json position-relative" data-snippet-clipboard-copy-content="{ &quot;plugins&quot;: { &quot;dogsheep-beta&quot;: { &quot;database&quot;: &quot;beta&quot;, &quot;config_file&quot;: &quot;dogsheep-beta.yml&quot;, &quot;template_debug&quot;: true } } } "><pre>{ <span class="pl-s"><span class="pl-pds">"</span>plugins<span class="pl-pds">"</span></span>: { <span class="pl-s"><span class="pl-pds">"</span>dogsheep-beta<span class="pl-pds">"</span></span>: { <span class="pl-s"><span class="pl-pds">"</span>database<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>beta<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span>config_file<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>dogsheep-beta.yml<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span>template_debug<span class="pl-pds">"</span></span>: <span class="pl-c1">true</span> } } }</pre></div> <p>The configuration settings for the plugin are:</p> <ul> <li><code>database</code> - the database file that contains your search index. If the file is <code>beta.db</code> you should set <code>database</code> to <code>beta</code>.</li> <li><code>config_file</code> - the YAML file containing your Dogsheep Beta configuration.</li> <li><code>template_debug</code> - set this to <code>true</code> to enable debugging output if errors occur in your custom templates, see below.</li> </ul> <h2><a id="user-content-custom-results-display" class="anchor" aria-hidden="true" href="#user-content-custom-results-display"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Custom results display</h2> <p>Each indexed item type can define custom display HTML as part of the <code>config.yml</code> file. It can do this using a <code>display</code> key containing a fragment of Jinja template, and optionally a <code>display_sql</code> key with extra SQL to execute to fetch the data to display.</p> <p>Here's how to define a custom display template for a tweet:</p> <div class="highlight highlight-source-yaml position-relative" data-snippet-clipboard-copy-content="twitter.db: tweets: sql: |- select tweets.id as key, 'Tweet by @' || users.screen_name as title, tweets.created_at as timestamp, tweets.full_text as search_1 from tweets join users on tweets.user = users.id display: |- &lt;p&gt;{{ title }} - tweeted at {{ timestamp }}&lt;/p&gt; &lt;blockquote&gt;{{ search_1 }}&lt;/blockquote&gt; "><pre><span class="pl-ent">twitter.db</span>: <span class="pl-ent">tweets</span>: <span class="pl-ent">sql</span>: <span class="pl-s">|-</span> <span class="pl-s"> select</span> <span class="pl-s"> tweets.id as key,</span> <span class="pl-s"> 'Tweet by @' || users.screen_name as title,</span> <span class="pl-s"> tweets.created_at as timestamp,</span> <span class="pl-s"> tweets.full_text as search_1</span> <span class="pl-s"> from tweets join users on tweets.user = users.id</span> <span class="pl-s"></span> <span class="pl-ent">display</span>: <span class="pl-s">|-</span> <span class="pl-s"> &lt;p&gt;{{ title }} - tweeted at {{ timestamp }}&lt;/p&gt;</span> <span class="pl-s"> &lt;blockquote&gt;{{ search_1 }}&lt;/blockquote&gt;</span></pre></div> <p>This example reuses the value that were stored in the <code>search_index</code> table when the indexing query was run.</p> <p>To load in extra values to display in the template, use a <code>display_sql</code> query like this:</p> <div class="highlight highlight-source-yaml position-relative" data-snippet-clipboard-copy-content="twitter.db: tweets: sql: |- select tweets.id as key, 'Tweet by @' || users.screen_name as title, tweets.created_at as timestamp, tweets.full_text as search_1 from tweets join users on tweets.user = users.id display_sql: |- select users.screen_name, tweets.full_text, tweets.created_at from tweets join users on tweets.user = users.id where tweets.id = :key display: |- &lt;p&gt;{{ display.screen_name }} - tweeted at {{ display.created_at }}&lt;/p&gt; &lt;blockquote&gt;{{ display.full_text }}&lt;/blockquote&gt; "><pre><span class="pl-ent">twitter.db</span>: <span class="pl-ent">tweets</span>: <span class="pl-ent">sql</span>: <span class="pl-s">|-</span> <span class="pl-s"> select</span> <span class="pl-s"> tweets.id as key,</span> <span class="pl-s"> 'Tweet by @' || users.screen_name as title,</span> <span class="pl-s"> tweets.created_at as timestamp,</span> <span class="pl-s"> tweets.full_text as search_1</span> <span class="pl-s"> from tweets join users on tweets.user = users.id</span> <span class="pl-s"></span> <span class="pl-ent">display_sql</span>: <span class="pl-s">|-</span> <span class="pl-s"> select</span> <span class="pl-s"> users.screen_name,</span> <span class="pl-s"> tweets.full_text,</span> <span class="pl-s"> tweets.created_at</span> <span class="pl-s"> from</span> <span class="pl-s"> tweets join users on tweets.user = users.id</span> <span class="pl-s"> where</span> <span class="pl-s"> tweets.id = :key</span> <span class="pl-s"></span> <span class="pl-ent">display</span>: <span class="pl-s">|-</span> <span class="pl-s"> &lt;p&gt;{{ display.screen_name }} - tweeted at {{ display.created_at }}&lt;/p&gt;</span> <span class="pl-s"> &lt;blockquote&gt;{{ display.full_text }}&lt;/blockquote&gt;</span></pre></div> <p>The <code>display_sql</code> query will be executed for every search result, passing the key value from the <code>search_index</code> table as the <code>:key</code> parameter and the user's search term as the <code>:q</code> parameter.</p> <p>This performs well because <a href="https://www.sqlite.org/np1queryprob.html" rel="nofollow">many small queries are efficient in SQLite</a>.</p> <p>If an error occurs while rendering one of your templates the search results page will return a 500 error. You can use the <code>template_debug</code> configuration setting described above to instead output debugging information for the search results item that experienced the error.</p> <h2><a id="user-content-displaying-maps" class="anchor" aria-hidden="true" href="#user-content-displaying-maps"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Displaying maps</h2> <p>This plugin will eventually include a number of useful shortcuts for rendering interesting content.</p> <p>The first available shortcut is for displaying maps. Make your custom content output something like this:</p> <div class="highlight highlight-text-html-basic position-relative" data-snippet-clipboard-copy-content="&lt;div data-map-latitude=&quot;{{ display.latitude }}&quot; data-map-longitude=&quot;{{ display.longitude }}&quot; style=&quot;display: none; float: right; width: 250px; height: 200px; background-color: #ccc;&quot; &gt;&lt;/div&gt; "><pre><span class="pl-kos">&lt;</span><span class="pl-ent">div</span> <span class="pl-c1">data-map-latitude</span>="<span class="pl-s">{{ display.latitude }}</span>" <span class="pl-c1">data-map-longitude</span>="<span class="pl-s">{{ display.longitude }}</span>" <span class="pl-c1">style</span>="<span class="pl-s">display: none; float: right; width: 250px; height: 200px; background-color: #ccc;</span>" <span class="pl-kos">&gt;</span><span class="pl-kos">&lt;/</span><span class="pl-ent">div</span><span class="pl-kos">&gt;</span></pre></div> <p>JavaScript on the page will look for any elements with <code>data-map-latitude</code> and <code>data-map-longitude</code> and, if it finds any, will load Leaflet and convert those elements into maps centered on that location. The default zoom level will be 12, or you can set a <code>data-map-zoom</code> attribute to customize this.</p> <h2><a id="user-content-development" class="anchor" aria-hidden="true" href="#user-content-development"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Development</h2> <p>To set up this plugin locally, first checkout the code. Then create a new virtual environment:</p> <div class="snippet-clipboard-content position-relative" data-snippet-clipboard-copy-content="cd dogsheep-beta python3 -mvenv venv source venv/bin/activate "><pre><code>cd dogsheep-beta python3 -mvenv venv source venv/bin/activate </code></pre></div> <p>Or if you are using <code>pipenv</code>:</p> <div class="snippet-clipboard-content position-relative" data-snippet-clipboard-copy-content="pipenv shell "><pre><code>pipenv shell </code></pre></div> <p>Now install the dependencies and tests:</p> <div class="snippet-clipboard-content position-relative" data-snippet-clipboard-copy-content="pip install -e '.[test]' "><pre><code>pip install -e '.[test]' </code></pre></div> <p>To run the tests:</p> <div class="snippet-clipboard-content position-relative" data-snippet-clipboard-copy-content="pytest "><pre><code>pytest </code></pre></div> </article></div>            

Links from other tables

  • 20 rows from repo in releases
Powered by Datasette · Queries took 1.5ms