p-search is a search engine written in Emacs Lisp with the design goals of being as costomizable and configurable as possible, a hallmark of the Emacs ecosystem. By “Search engine,” I mean a program that systematically organizes things to search, and coordinates queries, combining their results.
Before becomming enthralled by the minutiae of p-search we should first go over the rationale behind this package. To do so, we must consider what it means to search.
There’s a certain dance associated with the act of searching. It begins, as it must, in the mind. A particular state is envisioned: your lost keys in your hand, a software feature implemented, or understanding the workings of a certain software component. Your mind then maps out the entire set of actions leading to said state: you find your keys under your bed, or you find them in your pants pocket, or you ask your spouse and the keys are handed to you. Again in your mind, each outcome is given a probability of occurring.
You then proceed from one action to another, starting from the most likely, and proceeding to the unexpected. From glancing at the kitchen table and checking your pants pockets to checking the garbage can in the case that your toddler threw the keys away. Each unsucessful observation updates the map in your mind: upon removing the cushons from the sofa to find your keys and finding nothing, your probability that the keys are on the sofa drops, though not to zero, as the keys may have gone unnoticed.
Your search takes you frome a state of uncertainty to a resolution. Eventually you’ll reach your desired end state, or as many searches unfortunaetly conclude, you’ll end up with unexpected new hypothesis: you actually dropped your keys going on your run, that function you’re looking for was never written and you’ll have to write it, or your camera drone was seized by authorities and your best hope now is for the whole incident to be forgotten.
Let’s now take a closer look at each step in the search process, and how p-search attempts to capture it in code.