<!DOCTYPE html>
<html>

<head>
  <link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
  <link href='https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons' rel="stylesheet"
    type="text/css">
  <link href="https://cdn.jsdelivr.net/npm/@mdi/font@4.x/css/materialdesignicons.min.css" rel="stylesheet">
  <link href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" rel="stylesheet">
  <link href="https://cdn.jsdelivr.net/npm/@mdi/font@4.x/css/materialdesignicons.min.css" rel="stylesheet">
  <link href="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css" rel="stylesheet">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
  <style>
    .v-toolbar__content {
      padding-left: 0;
    }
  </style>
</head>

<body>
  <div id="app">
    <v-app>
      <v-app-bar app color="blue darken-3" dark>
        <v-col cols="1">
          <v-toolbar-title class="ml-0 pl-4">
            <span class="hidden-sm-and-down">BERT Search</span>
          </v-toolbar-title>
        </v-col>
        <v-col cols="5">
          <v-text-field v-model="query" v-on:keyup.enter="submit" flat solo-inverted hide-details
            prepend-inner-icon="search" label="Search" class="hidden-sm-and-down"></v-text-field>
        </v-col>
        <div class="flex-grow-1"></div>
      </v-app-bar>
      <v-content>
        <v-row class="ml-0">
          <v-col cols="12" md="6" offset-md="1" offset-lg="1" offset-xl="1">
            <template v-if="'hits' in result">
              <v-card max-width="700" flat v-for="(item, index) in result.hits.hits" :key="index">
                <v-card-title>[[ item._source.title ]]</v-card-title>
                <v-card-text>[[ item._source.text.slice(0, 300) ]]...</v-card-text>
                <!--
                <v-card-actions>
                  <v-chip class="primary">[[ item._score ]]</v-chip>
                </v-card-actions>
              -->
              </v-card>
            </template>
          </v-col>
        </v-row>
      </v-content>
    </v-app>
  </div>

  <script src="https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.js"></script>
  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  <script>
    axios.defaults.xsrfCookieName = 'csrftoken';
    axios.defaults.xsrfHeaderName = 'X-CSRFToken';
    const base_url = window.location.href;
    new Vue({
      el: '#app',
      vuetify: new Vuetify(),
      delimiters: ['[[', ']]'],
      data: {
        query: '',
        result: []
      },
      created() {
        this.query = '郑伊健东京迎娶蒙嘉慧'
        this.search()
      },
      methods: {
        search() {
          axios.get(`${base_url}search?q=${this.query}`).then(response => {
            this.result = response.data;
          })
        },
        submit() {
          if (this.query == '') {
            this.result = [];
            return;
          }
          this.search()
        }
      }
    })
  </script>
</body>

</html>