advanced search in Preview

searching_for_light


Unlike Adobe Acrobat, you won’t find any complicated advanced search boxes in Preview, but that doesn’t mean you have any less power to find exactly what you want. Feel free to open up a pdf that you can play around with as we go along.

Finding stuff
Preview does all its searching in the spotlight-like filter field in the top right, and you access it either by clicking in it or hitting ‘command-F’.

Simply typing in a few letters will return every page that contains that string, either as a word or a partial word. If you want to restrict the results to complete words – say you type in ’cause’ but you don’t want it to return ‘because’, then add double quote marks around what you type.

"cause"

If you add another word (or words), also in double quotes, this is effectively telling Preview to return only those pages that contain all those complete words on the same page. Thus

"cause" "pattern" "function"

will only return pages in your pdf document that contain all three of those terms. This is the same effect you get when you put the ampersand ‘&’ between words (the logical AND), but the & is automatically implied by default, so there’s no need to actually type it.

What if you want to return all pages that have either “cause” or “function” in them? In this case, you use the ‘|’ sheffer stroke (hold down shift and hit the backward slash key, up their above the return key!).

Note for the techies: Preview doesn’t distinguish between NOR and NAND. Though both are valid input, one sheffer stroke will return the same as two.

As with the logical ‘AND’ function, you can have as many terms as you want. For example, if you wanted to return every page that had a numeral in it, you could use

"1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "0"

That would return every instance of any one of those digits on their own, but it wouldn’t return a page that had, say, ‘2014’ in it. Remember that the quote marks indicate whole expressions, not parts. To get any number, do the same without the quotes:

1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0

You could even combine this with word searches:

1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | one | two | three | four | five | six | seven | eight | nine | "ten" | eleven | twelve | thirteen | fourteen | fifteen | sixteen | seventeen | eighteen | nineteen | twenty | thirty | forty | fifty | sixty | seventy | eighty | ninety | hundred | thousand | million | billion | trillion | zero | nought | nil

That would return every mention of any number in numerals or words. Note that “ten” is delimited as a complete word due to the number of false positives that would arise from words with those three letters (heighten, often, tendency, etc). Also notice the various synonyms for ‘zero’ at the end of the search term. Even so, it isn’t quite complete – the assiduous search-hound would probably want to add ordinals, ‘1st’, ‘first’, ‘2nd’, ‘second’ and so on, but I’ll leave that as an exercise for the reader.

Organising results
OK, so you’ve got your results, what can you do with them? First of all, note that you’ve got some options above the search sidebar. You can list by page order from beginning to end of the document, or by number of hits per page with ‘Search Rank’. Highest number of matches on a page appears at the top of the results and the rest follow in descending order.

Screen Shot 2014-03-22 at 00.10.14

Secondly, you can cycle backwards and forward through the hits on each page by using ‘command-G’ and ‘command-shift-G’, respectively. That’s a whole lot less laborious than clicking the tiny forward and backward arrows under the filter field, but that way is available too.

filter bar

The filter field
Finally, don’t forget that you can move the cursor around in the filter field with a few shortcuts: both ‘control-E’ and command-right arrow will put the cursor to end of the search term, while ‘control-A’ and command-left arrow will put it at the beginning. You can also use ‘control-K’ to delete everything from the cursor to the end of the search term, which can be handy if you have a lengthy search term that you want to cut in half. Move the cursor to where you want the search term to end, and hit ‘control-K’ to delete all subsequent characters.

Hopefully, that should give you some pretty good ideas on how to power search in Preview. Who needs ‘advanced search’ dialog boxes? Not us! 🙂

featured picture: searching for light by HealingRock

Advertisement

About philastokes

Independent Software Developer, Technical Writer and Researcher at SentinelOne. Explaining the unexplainable with images, video and text. Scripting anything imaginable in AppleScript, Bash, Python and Swift.

Posted on March 22, 2014, in Preview and tagged , , , , , . Bookmark the permalink. Comments Off on advanced search in Preview.

Comments are closed.

%d bloggers like this: