Skip to content

Instantly share code, notes, and snippets.

@rayantony
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save rayantony/f7a60587a4f2ec817024 to your computer and use it in GitHub Desktop.

Select an option

Save rayantony/f7a60587a4f2ec817024 to your computer and use it in GitHub Desktop.
CSE pagemaps and sitemaps

##sitemaps cse and pagemaps

from https://developers.google.com/custom-search/docs/structured_data#addtopage

Add PageMap data to a Sitemap

If you don't want to include PageMap data in the HTML of your pages, you can add PageMap data to a Sitemap and submit that Sitemap for on-demand indexing using the Custom Search Control Panel.

Here's an example of a Sitemap that includes PageMap information for two URLs: http://www.example.com/foo and http://www.example.com/bar.

http://www.example.com/foo Dragon 3.5 http://www.example.com/bar Ribs 4.0

Submit PageMap data using the Custom Search Control API

To submit PageMap data using the Custom Search Control API, send an HTTP POST message, using the text/xml content type, to: http://cse.google.com/api/default/index/<CSE_ID>. Include PageMap data in the message body, like this:

Monkeys 4.0/5.0 1000 100 Parrots 4.5/5.0 2000 200

Private PageMaps

In some cases, you may not want custom attributes returned in your search engine's query results XML, because those are publicly visible by default. In this case, you can create a private PageMap by adding an AccessKey to the DataObject you want to protect, and sending the PageMap directly to Google using the on-demand indexing API. Only web searches with a matching AccessKey parameter will get that DataObject in results.

Here's an example of an AccessKey in use:

myprivate12345 1000 100

An AccessKey can consist of no more than 30 alphanumeric characters.

To retrieve protected data, specify the AccessKey in the pgmpk parameter. For example, if your AccessKey is myprivate12345, your query URL might look like this:

https://www.google.com/cse?cx=[CSEID]&q=animal&output=xml&pgmpk=myprivate12345

See a full list of supported parameters.

To restrict results to protected data, update your search URL to append the AccessKey value to the more:pagemap:TYPE-NAME:VALUE operator, like this:

https://www.google.com/cse?cx=[CSEID]&output=xml&q=animal+more:pagemap:myprivate12345-document-rating&pgmpk=myprivate12345

To sort by protected data, update your search URL to append the AccessKey value to the &sort=TYPE-NAME:DIRECTION parameter, like this:

https://www.google.com/cse?cx=[CSEID]&q=animal&output=xml&sort=myprivate12345-document-rating&pgmpk=myprivate12345

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment