Section 29.9 Google Search
Note: as of 2022-10-27 we have search supported by an online service from Google and a client-side (“native”)version supported by Javascript (
Section 29.8 ). Development and support will favor the latter.
Search facilities can be enabled through
Google Custom Search Engine . Please, please report any discrepancies in the following instructions as the setup interface at Google changes out from underneath us. These instructions have been updated as of 2020-10-01.
Besides being useful for search facilities, setting up a search engine might be a good way to alert Google of something newly available, and initiate your book’s rise up the search results rankings.
List 29.9.1. Configuring Google Custom Search
Create an account with Google (GMail, YouTube, etc.) and make sure you are signed in.
Visit
GCSE and add a new search engine via
New Search Engine
.
Provide a
URL for the top-level domain name/directory for your book/document. Everything below this will be indexed. We have taken some care to mark knowl content in a way compatible with the search facility, but there is more work to do here.
Give the engine a GCSE-specific name, so you can tell later which one it is when you have several.
Under Edit Search Engine
in the Basics
tab locate Search engine ID
which has a string that uniquely identifies your new search engine. Save this, you’ll need to make it part of your PreTeXt document.
Under the Users
tab add co-authors or trusted backup personnel.
Fiddle with Edit Search Engine > Look and Feel
at your own risk! Only the defaults are tested and supported.
Provisions for removing advertisements for non-profit sites seem to have changed. If your university already contracts with Google, you should investigate having a “SuperAdmin” at your institution so this setup for you, and make you a trusted collaborator. Then it should be an easy matter to turn off advertisements.
List 29.9.2. Configuring PreTeXt for Google Search
Because these sign-ups are dependent on your site, this is a publisher activity, and hence configured with the publication file (
Section 26.1 ), see
Subsection 44.4.12 for details.
The Search engine ID
you saved from above is referenced in Google’s code as a cx
number. An example looks like 482cf73dc05bed674
(older examples looked like 002673997130187229905:qjo2y0jplyu
). In which case your publication file would have an element under html
like
<search google-cx="482cf73dc05bed674"/>
The search/@google-cx
attribute will alert the PreTeXt conversion and fully enable and implement search. You are done, and everything should just work. You should see a Google-branded search box to the top right of each of your pages. (We have no control over the branding.)
Time to rebuild your
HTML output and make the improved version available.