I used the search box in the navigation bar to search for pages in this blog.
It had been working well, but a month ago, the box searched for webpages other than those in this blog.
How to limit the search to pages within this site only?
I read the generated HTML code for the search box, and compared the difference between a version of an HTML file in November, and another version in early October. However, I couldn’t find out the reason.
A temporary “fix”
Local re-generation and preview of site contents on *nix
I noticed that the custom search failed after I had uploaded a Git commit which had been written on M$ Win* 7.1 Therefore, when I was using my *nix desktop, I re-generated this site and previewed it.
I saw that The search box worked fine this time.
Then, I didn’t hesitate to deploy this site to GitHub Pages.2
Confirmed the “fix”
I browsed this blog on GitHub Pages to make sure that the problem had been “fixed”.
Failed to find the cause
I guessed that this was due to the difference between *nix and M$ Win*, after failing to find any clue from comparing the source code in different versions.
Problem appeared again
Repeating the “fix”
Three days ago, after pulling the recent commits from the remote repository of this blog on GitHub, I wrote another post on Ubuntu, and locally generated this site before publishing the post.5 Unluckily, the search box still failed to work.
Moreover, I couldn’t understand why the custom search failed in Mozilla Firefox and Google Chrome, but worked in M$ Internet Explorer.
Fix the problem
I found the page Add a Search Box from the Columbia
University. I followed the steps for limiting the search by
site.6 Without the line
<input type="hidden" name="as_dt"
source/_includes/navigation.html, the search box
still work fine.
Test the fix
In the past, I used
rake preview to detect any errors. As the
number of posts and pages grew, this method has become inefficient.
While testing the instructions in this guide, I put the HTML code for
the custom search box in an HTML file, and viewed the effects in
Firefox. The URL variable
ei was still there, but the custom search
was restricted to this site only.
After solving this problem, I discovered another solution in the pull requests of Octopress.7
(Added on Dec 21, 2014)
Now, the problem has been fixed.8