Skip to content

Commit

Permalink
Update Alfred-Workflow and rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
deanishe committed Sep 12, 2017
1 parent 2428aff commit c3b479f
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 44 deletions.
2 changes: 0 additions & 2 deletions .gitignore
@@ -1,5 +1,3 @@
Gutenberg Book Search.alfredworkflow.zip

# Created by https://www.gitignore.io/api/vim,python,sublimetext

### Python ###
Expand Down
Binary file not shown.
20 changes: 16 additions & 4 deletions README.md
@@ -1,12 +1,20 @@
# Alfred/sqlite demo workflow #
Alfred/sqlite demo workflow
===========================

Search the index of Project Gutenberg ebooks from Alfred.

![](https://github.com/deanishe/alfred-index-demo/raw/master/demo.gif "")

Demonstrates the usage of sqlite full-text search in a workflow and the blinding speed this offers.

## Usage ##
Download
--------

Grab the workflow from [GitHub releases][latest].


Usage
-----

- `books <query>` — Search the Gutenberg catalogue for `<query>`

Expand All @@ -17,7 +25,9 @@ You can use wildcard, boolean and field-specific queries:
- `books criti*`
- `books title:criti* AND author:kant`

## How fast? ##

How fast?
---------

Here's some sample log output using [a database of ~45,000 ebooks](https://raw.githubusercontent.com/deanishe/alfred-index-demo/master/src/books.tsv) from [Project Gutenberg](http://www.gutenberg.org/):

Expand Down Expand Up @@ -88,4 +98,6 @@ Here's some sample log output using [a database of ~45,000 ebooks](https://raw.g
11:11:20 books.py:110 INFO 0 results for `philosophy author:aristotl` in 0.002 seconds
11:11:20 books.py:110 INFO 0 results for `philosophy author:aristotle` in 0.002 seconds
11:11:22 books.py:110 INFO 15 results for `author:aristotle` in 0.002 seconds
```
```

[latest]: https://github.com/deanishe/alfred-index-demo/releases/latest
9 changes: 4 additions & 5 deletions src/books.py
@@ -1,15 +1,14 @@
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright © 2014 deanishe@deanishe.net
# Copyright (c) 2014 deanishe@deanishe.net
#
# MIT Licence. See http://opensource.org/licenses/MIT
#
# Created on 2014-07-03
#

"""
"""
"""Workflow Script Filter to show search results in Alfred."""

from __future__ import print_function, unicode_literals

Expand Down Expand Up @@ -42,10 +41,10 @@ def rank(matchinfo):
# http://www.sqlite.org/fts3.html#matchinfo
# and struct defaults to machine byte order
bufsize = len(matchinfo) # Length in bytes.
matchinfo = [struct.unpack(b'I', matchinfo[i:i+4])[0]
matchinfo = [struct.unpack(b'I', matchinfo[i:i + 4])[0]
for i in range(0, bufsize, 4)]
it = iter(matchinfo[2:])
return sum(x[0]*w/x[1]
return sum(x[0] * w / x[1]
for x, w in zip(zip(it, it, it), weights)
if x[1])
return rank
Expand Down
5 changes: 2 additions & 3 deletions src/catalogue_to_tsv.py
@@ -1,15 +1,14 @@
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright © 2014 deanishe@deanishe.net
# Copyright (c) 2014 deanishe@deanishe.net
#
# MIT Licence. See http://opensource.org/licenses/MIT
#
# Created on 2014-07-03
#

"""
Convert the Gutenberg RDF data dump to a TSV file.
"""Convert the Gutenberg RDF data dump to a TSV file.
The script expects the data dump from
http://www.gutenberg.org/wiki/Gutenberg:Feeds#The_Complete_Project_Gutenberg_Catalog
Expand Down
5 changes: 2 additions & 3 deletions src/config.py
@@ -1,15 +1,14 @@
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright © 2014 deanishe@deanishe.net
# Copyright (c) 2014 deanishe@deanishe.net
#
# MIT Licence. See http://opensource.org/licenses/MIT
#
# Created on 2014-07-03
#

"""
"""
"""Common settings."""

from __future__ import unicode_literals

Expand Down
9 changes: 4 additions & 5 deletions src/index.py
@@ -1,15 +1,14 @@
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright © 2014 deanishe@deanishe.net
# Copyright (c) 2014 deanishe@deanishe.net
#
# MIT Licence. See http://opensource.org/licenses/MIT
#
# Created on 2014-07-03
#

"""
Read in data from `books.tsv` and add it to the search index database.
"""Read in data from `books.tsv` and add it to the search index database.
See `catalogue_to_tsv.py` for the generation of the `books.tsv` file.
"""
Expand Down Expand Up @@ -58,8 +57,8 @@ def update_index_db():
count = 0
with con:
cur = con.cursor()
with open(DATA_FILE, 'rb') as file:
reader = csv.reader(file, delimiter=b'\t')
with open(DATA_FILE, 'rb') as fp:
reader = csv.reader(fp, delimiter=b'\t')
for row in reader:
id_, author, title, url = [v.decode('utf-8') for v in row]
id_ = int(id_)
Expand Down
50 changes: 28 additions & 22 deletions src/info.plist
Expand Up @@ -30,6 +30,25 @@
<string>Gutenberg Book Search</string>
<key>objects</key>
<array>
<dict>
<key>config</key>
<dict>
<key>browser</key>
<string></string>
<key>spaces</key>
<string></string>
<key>url</key>
<string>{query}</string>
<key>utf8</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.action.openurl</string>
<key>uid</key>
<string>D56B2A64-50BA-464C-8D64-48EB68D5B376</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand All @@ -44,7 +63,7 @@
<key>escaping</key>
<integer>102</integer>
<key>keyword</key>
<string>besser</string>
<string>books</string>
<key>queuedelaycustom</key>
<integer>1</integer>
<key>queuedelayimmediatelyinitially</key>
Expand All @@ -56,9 +75,9 @@
<key>runningsubtext</key>
<string>Searching books…</string>
<key>script</key>
<string>/usr/bin/python books.py "{query}"</string>
<string>/usr/bin/python books.py "$1"</string>
<key>scriptargtype</key>
<integer>0</integer>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>subtext</key>
Expand All @@ -77,45 +96,32 @@
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>browser</key>
<string></string>
<key>spaces</key>
<string></string>
<key>url</key>
<string>{query}</string>
<key>utf8</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.action.openurl</string>
<key>uid</key>
<string>D56B2A64-50BA-464C-8D64-48EB68D5B376</string>
<key>version</key>
<integer>1</integer>
</dict>
</array>
<key>readme</key>
<string></string>
<key>uidata</key>
<dict>
<key>D56B2A64-50BA-464C-8D64-48EB68D5B376</key>
<dict>
<key>note</key>
<string>Open book page in browser</string>
<key>xpos</key>
<integer>240</integer>
<key>ypos</key>
<integer>30</integer>
</dict>
<key>E2E84778-9472-48A7-851A-87F07879DA5C</key>
<dict>
<key>note</key>
<string>Search Gutenberg.org ebooks</string>
<key>xpos</key>
<integer>40</integer>
<key>ypos</key>
<integer>30</integer>
</dict>
</dict>
<key>version</key>
<string>1.4</string>
<key>webaddress</key>
<string></string>
</dict>
Expand Down

0 comments on commit c3b479f

Please sign in to comment.