Skip to content

Commit 136bc4b

Browse files
committed
Add support for searching on multiple keywords separated with space.
1 parent 8e02fca commit 136bc4b

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

README.md

+4-8
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@ This workflow for [Alfred 2](http://www.alfredapp.com/) will search you snippets
88

99
![](https://github.com/pahen/Snippets.alfredworkflow/raw/master/img/search.png)
1010

11-
```ENTER``` = Copy to clipboard
11+
```ENTER``` to copy to clipboard.
1212

13-
```CMD + ENTER``` = Copy & paste
13+
```CMD + ENTER``` to copy & paste.
1414

15-
```ALT + ENTER``` = View as Large Type
15+
```ALT + ENTER``` to view as Large Type.
1616

17-
You can also create new snippets from a text selection anywhere by pressing ```CTRL + ALT + CMD + S```.
18-
19-
## TODO
20-
21-
Add support for searching on multiple keywords separated with space.
17+
You can also create a new snippet from a text selection in a application by pressing ```CTRL + ALT + CMD + S```.

Snippets.alfredworkflow

62 Bytes
Binary file not shown.

img/search.png

-29.7 KB
Loading

src/search.php

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
$keyword = $argv[1];
3+
$keywords = $argv[1];
44
$doc = new DOMDocument;
55

66
// this file has been serialized from Core Data (http://en.wikipedia.org/wiki/Core_Data).
@@ -17,12 +17,14 @@
1717
echo '<?xml version="1.0"?>';
1818
echo '<items>';
1919

20+
// iterate over all snippets
2021
foreach ($xpath->query('//object[@type="SNIPPET"]') as $snippet) {
21-
// ignore deleted snippets
22+
// ignore deleted ones
2223
if ($xpath->query('./attribute[@name="dateremoved"]', $snippet)->item(0)) {
2324
continue;
2425
}
2526

27+
$match = true;
2628
$tags = array();
2729
$name = $xpath->query('./attribute[@name="name"]', $snippet)->item(0)->nodeValue;
2830
$tagIds = $xpath->query('./relationship[@name="tags"]', $snippet)->item(0)->getAttribute('idrefs');
@@ -35,8 +37,15 @@
3537
}
3638
}
3739

38-
// do a case-insensitive match and see if we have a snippet with a matching tag, name, or code
39-
if (in_array(strtolower($keyword), array_map('strtolower', $tags)) || stristr($name, $keyword) || stristr($code, $keyword)) {
40+
// do a case-insensitive match on all keywords and see if we have a snippet with a matching tag, name, or code
41+
foreach(explode(' ', $keywords) as $keyword) {
42+
if (!in_array(strtolower($keyword), array_map('strtolower', $tags)) && !stristr($name, $keyword) && !stristr($code, $keyword)) {
43+
$match = false;
44+
}
45+
}
46+
47+
// we got a match!
48+
if ($match) {
4049
$title = $name;
4150

4251
if (!empty($tags)) {

0 commit comments

Comments
 (0)