By default, Spotlight indexes most of your files, and they can be accessed by entering search terms. While this is a convenient feature since you do not have to remember the exact location of your files, your secret files may be exposed. Luckily, it is possible to configure Spotlight to exclude specific files from the search result. Here is how to do it.
Even though this tutorial is written for OS X El Capitan, it should work on OS X Yosemite as well.
At the time of this writing, OS X El Capitan is still in beta, so the steps might look a bit different in the public release of the OS. If you want to try out OS X El Capitan, head to this page, and follow the instructions.
1. Move your mouse to the top left of the screen, click the Apple logo, and select the System Preferences option in the context menu.
2. In the System Preferences window, select the Spotlight option in the first row.
3. The Spotlight window will be divided into two tabs: Search Results and Privacy. Select the Privacy tab, and click the plus button below the empty box. The box is there to list all the folders that you want to be excluded from the Spotlight search. Initially, there are no hidden folders, so the box is empty.
4. In the pop-up finder window, navigate to the folder that you want to hide, highlight it, and click Choose. If you have files that do not belong to any folders, you have to create a new folder and put your files in it first.
5. Come back to the previous window, and confirm that the newly added folder is there.
6. Close the system preferences window, and then do a search in Spotlight to make sure that your secret files do not show up in the results.