{% extends "skeleton.html" %}
{% block page_title %}Full Text Search{% endblock %}

{% block page_head %}
  <script>{% include "search_index.js" %}</script>
  <style type="text/css">{% include "search.css" %}</style>
{% endblock %}

{% block body %}
<div id="search">
  <h3><a href="/search">Full Text Search</a> > {{ index }}</h3>

<form method="get">
  <input type="hidden" name="index" value="{{ index }}"/>
  <div>
    <div>Query string:</div>
    <textarea name="query" rows="3" cols="70">{{ query }}</textarea>
    <p>
      Learn more about
      <a href="https://developers.google.com/appengine/docs/python/search/overview#Query_Language_Overview"
        target="_blank">text search syntax</a>.
    </p>
  </div>
  <div>
    Namespace:
    <div>
      <input name="namespace" type="text" value="{{ namespace }}">
      <p>
        Leave empty for default namespace.
      </p>
    </div>
  </div>
  <div>
    <input type="submit" class="ae-button" value="Run Query">
  </div>
</form>
<br>

{% if values.documents %}
  <form action="/search/index" method="post">
  <input type="hidden" name="xsrf_token" value="{{ xsrf_token }}"/>
  <input type="hidden" name="index" value="{{ index }}"/>
  <input type="hidden" name="namespace" value="{{ namespace }}"/>
  <input type="hidden" name="start" value="{{ start }}"/>
  <input type="hidden" name="numdocs" value="{{ values.documents|length }}"/>
  <table class="ae-table">
    <thead>
      <tr>
        <th><input id="alldocs" type="checkbox"/></th>
        <th>Document Id</th>
        {% for field in values.field_names %}
        <th>{{ field }}</th>
        {% endfor %}
      </tr>
    </thead>
    <tbody>
      {% for document in values.documents %}
      <tr>
         <td><input type="checkbox" name="doc_id" value="{{ document.doc_id|urlencode }}"/></td>
        <td>
          <a href="/search/document?index={{ index|urlencode }}&amp;namespace={{ namespace|urlencode }}&amp;id={{ document.doc_id|urlencode }}">{{ document.doc_id }}</a>
        </td>
        {% for field in document.fields %}
          <td>
            {{ field|string|truncate(32, True) }}
          </td>
        {% endfor %}
      </tr>
      {% endfor %}
    </tbody>
  </table>
  {% if paging %}
  <div class="pagination">
    {% if previous_url %}
    <a href="{{ previous_url }}">&lsaquo; Previous</a>{% endif %}
    {% if next_url %}<a href="{{ next_url }}">Next &rsaquo;</a>{% endif %}
  </div>
  {% endif %}
  <div>
    <input id="delete_button" type="submit" class="ae-button" value="Delete"/>
  </div>
  </form>
{% else %}
  {% if query %}
  No documents in the index match the query.
  {% else %}
  No documents found in the index.
  {% endif %}
{% endif %}
</div>
{% endblock %}
