Skip to content
Snippets Groups Projects
SearchResults.vue 1.21 KiB
Newer Older
Ole Voldsæter's avatar
Ole Voldsæter committed
<template>
Ole Voldsæter's avatar
Ole Voldsæter committed
    <h2 v-if="hits.length">Søkeresultater</h2>
    <ul class="hits">
      <Preview v-for="(result, index) in hits" :key="index" :searchHit="result" @click.native="article_link_click(result._source)">
      </Preview>
Ole Voldsæter's avatar
Ole Voldsæter committed
    </ul>
Ole Voldsæter's avatar
Ole Voldsæter committed
</template>

<script>
import helpers from '../utils/helpers.js'
import Preview from './Preview.vue'

Ole Voldsæter's avatar
Ole Voldsæter committed
export default {
  name: 'SearchResults',
  props: {
    hits: Array,
    lang: String
Ole Voldsæter's avatar
Ole Voldsæter committed
  },
  computed: {
    extended_results: function(){
      return this.hits.map(
        function(hit){
          return {
              id: hit._id,
              label: hit._source.lemmas.map(x => x.lemma).join(', '),
Ole Voldsæter's avatar
Ole Voldsæter committed
              classification: helpers.group_list(hit._source.lemmas),
              article: hit._source
Ole Voldsæter's avatar
Ole Voldsæter committed
          }
      })
    }
Ole Voldsæter's avatar
Ole Voldsæter committed
  },
  methods: {
    article_link_click: function(article) {
      this.$router.push('' + article.article_id)
      this.$emit('search-hit-click', article)
  },
  components: {
    Preview
Ole Voldsæter's avatar
Ole Voldsæter committed
  }
}

</script>
<style>
  .hits  .preview {
    margin: 10px;
    padding: 5px;
    cursor: pointer;
  }

  .hits  .preview h4 {
    color: rgb(0, 0, 238);
    text-decoration: underline;
  }

  .hits {
    margin-top: 20px;
  }
</style>