2015-06-23 20 views
2

我們在我們的網站上使用Schema.org SearchAction,希望在Google搜索結果中顯示附加鏈接搜索框。我已經完全按照它在Google's Developer Page上所說的那樣來執行代碼,但是當我在Google's Test Tool中進行測試時,它仍然返回錯誤。Schema.org SearchAction error for Google Sitelinks搜索框:「valueName:missing and required」

這裏是我使用的代碼:

<div itemscope itemtype="http://schema.org/WebSite"> 
    <meta itemprop="url" content="http://www.examplesite.com"/> 
    <form itemprop="potentialAction" itemscope itemtype="http://schema.org/SearchAction"> 
     <meta itemprop="target" content="http://www.examplesite.com/catalogsearch/result/?q={q}"/> 
     <input itemprop="query-input" type="text" name="q"> 
     <input type="submit"> 
    </form> 
</div> 

這是我得到的錯誤:

Structured Data Testing Tool Error

我想,如果我可以使用微因爲到目前爲止我們所有的標記都使用它。有誰知道我怎麼能解決這個問題?

回答

1

更新:這是Google的測試工具中的a bug。問題的標記(和谷歌自己的文檔)現在再次運行。所以不需要下面的選擇。


目前尚不清楚這是否只是一個暫時的錯誤與他們Structured Data Testing Tool,或者如果他們對Sitelinks Search Box文檔不再準確。

如果你認爲他們的規則變化(和他們忘記更新文檔),你可以通過提供PropertyValueSpecification項目及其valueName財產(如錯誤信息提示)修正:

<div itemscope itemtype="http://schema.org/WebSite"> 
    <link itemprop="url" href="http://www.example.com"/> <!-- changed from 'meta' to 'link', as it’s required by HTML5 and Microdata --> 
    <div itemprop="potentialAction" itemscope itemtype="http://schema.org/SearchAction"> 
     <meta itemprop="target" content="http://www.example.com/catalogsearch/result/?q={q}"/> 
     <div itemprop="query-input" itemscope itemtype="http://schema.org/PropertyValueSpecification"> 
      <meta itemprop="valueName" content="q"/> 
     </div> 
    </div> 
</div> 

FWIW,這爲結構化數據測試工具中的「附加鏈接搜索框」提供了「一切都好」。

+0

目標中的{q}和valueName中的q是否需要與用戶輸入的實際搜索值匹配?這是我從文檔中完全不瞭解的。所以我只是靜態設置它以匹配我們的搜索結果頁面用於搜索的字母。 – njm5785

+0

花括號'{'和'}'裏面的字符串只是一個佔位符,你選擇哪一個並不重要(它只需要匹配'valueName'的值)。在您的示例中,搜索的查詢參數與佔位符相同,但不一定是。例如,你可以使用這個'target' URI:'http://www.example.com/catalogsearch/result/?q= {foobar}',然後你必須使用這個'valueName'值: 'foobar'。是的,它是靜態的(它只是告訴搜索引擎必須替換哪些字符串,以便爲您的網站生成有效的搜索網址)。 – unor

+0

@Nick:我更新了我的答案:您的原始標記現在再次生效。 – unor