1

Google App Engine Search API (Python) を使用しており、jinja2 テンプレートで特定の search_document フィールドを出力できるようにしたいと考えています。テンプレートでこの表記を使用して、検索ドキュメントの「コメント」フィールドを印刷しようとしています。

{{ scored_document.comment }}

私はこの出力が欲しい:

test

しかし、代わりに私はこの出力を得ています:

[search.TextField(name=u'comment', value=u'test')]

「コメント」のだけを取得するための正しい構文は何ですか?

APIドキュメントは、メンバー(リストオブジェクト)を介してのみこの値を取得できることを示しているようですが.fields、この表記法も機能していないようです:

{{ scored_document.fields.comment }}

Google がgithubで提供している Search API サンプルを拡張しているだけです。

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <link rel="stylesheet" type="text/css" href="/static/css/main.css"/>
    <title>Search Demonstration App</title>
  </head>
  <body style="margin:20px;">

    <form action="/sign" method="post">
      <div>Search Demo</div>
      <div><textarea name="search" rows="1" cols="60"></textarea></div>
      <div><input type="submit" value="Search"/></div>
      <div><textarea name="content" rows="3" cols="60"></textarea></div>
      <div><input type="submit" value="Comment"/></div>
    </form>

    {{number_returned}} of {{results.number_found}} comments found <p>
    {% for scored_document in results %}

      <!-- Just want **value** of comment here: -->
      {{ scored_document.comment }}

      <p>
    {% endfor %}

    <a href="{{ url }}">{{ url_linktext }}</a>

  </body>
</html>
4

1 に答える 1

1

フィールドの「値」プロパティが必要です。

{{ scored_document.comment.value }}
于 2013-05-14T17:21:47.890 に答える