Search code examples
google-custom-search

How can I use pagemap with google custom search refinements?


I'm trying to add refinements to my google custom search. I have meta tags on just about every page of the site, such as

<meta name="type-id" content="241" />

Where there are many different types, and I want to have one refinement for each type. In the docs, it says

You can also use these more:pagemap: operators with refinement labels

But I have been unable to do that. Note that I have had success using more:pagemap:metatags-type-id:241 in the search input, or as a webSearchQueryAddition - but despite googles docs, I haven't been able to get it to work with a refinement.

Here's a sample from my cse.xml (removing some attributes from the CustomSearchEngine tag):

<?xml version="1.0" encoding="UTF-8"?>
<CustomSearchEngine>
  <Title>Test</Title>
  <Context>
    <Facet>
      <FacetItem>
        <Label name="videos" mode="FILTER">
          <Rewrite>more:p:metatags-article-keyword:121</Rewrite>
        </Label>
        <Title>Videos</Title>
      </FacetItem>
    </Facet>
  </Context>
</CustomSearchEngine>

Is this supposed to work? Am I using wrong syntax in the rewrite rule? Has anyone else done something like this?


Solution

  • Your label in the facet should be mode="BOOST" if you want to restrict to a structured data field within the scope of your engine.

    <Facet>
       <FacetItem>
          <Label name="videos" mode="BOOST">
              <Rewrite>more:p:metatags-article-keyword:121</Rewrite>
          </Label>
          <Title>Videos</Title>
       </FacetItem>
    </Facet>