travis-r6s / gridsome-plugin-flexsearch

Add lightning fast search to Gridsome with FlexSearch
24 stars 7 forks source link

Asking for a little help setting up with a section built with strapi #64

Closed findborg closed 3 years ago

findborg commented 3 years ago

I am trying to merge a section from that uses the strapi backend to generate content. I was wondering if anyone could help me get the results to show up?

I can not get the const done right. I have tried all day today to get it to work. Sometimes you just need a lesson.

Here is the query part. I left out my miserable attempt at the const.


query Search {
  allPost {
    edges {
      node {
        id
        path
        title
        summary
        headings {
          depth
          value
          anchor
        }
      }
    }
  }
  allDocumentation {
    edges {
      node {
        id
        path
        title
      }
    }
  }

  strapi {
    projects{
      id
      title
      slug
      description

      }
    }

}
</static-query>

<script>
import SearchFocus from './SearchFocus'

export default {
  components: {
    SearchFocus,
  },
  computed: {
    pages () {
      let result = [];
      const allPost = this.$static.allPost.edges.map(edge => edge.node);
      allPost.forEach(page => {
        result.push({
          path: page.path,
          title: page.title,
          summary: page.summary
        });
      });
      const allDocs = this.$static.allDocumentation.edges.map(edge => edge.node);
      allDocs.forEach(page => {
        result.push({
          path: page.path,
          title: page.title
        });
      });

      return result;
    }
  },```

The const for allPost and allDocs works perfect.  But,  strapi does not follow the edge.node

Here is the Graph schema produced from the strapi query not including the two that work.

```{
  "data": {
    "strapi": {
      "projects": [
        {
          "id": "1",
          "title": "Pepperoni pizza",
          "slug": "pepperoni-pizza",
          "description": "My last cooking project, and my first pizza. Pepperoni is characteristically soft, slightly smoky, and bright red in color. Thinly sliced pepperoni is a popular pizza topping in American pizzerias."
        },
        {
          "id": "2",
          "title": "A company wants to follow B-corp guidlines",
          "slug": "b-corporation-as-a-role-model",
          "description": "Have you ever had a role model in your life?  I was reading an article about Lemonade the other day and found something very interesting.  As a matter of fact,  It was all about B corporations and how to become one. "
        },
        {
          "id": "3",
          "title": "Vue.js Todo List",
          "slug": "vue-js-todo-list",
          "description": "I needed to get better at managing my daily tasks. So I build a nice little todo list application. It performs all CRUD operations."
        },
        {
          "id": "4",
          "title": "Search engine or Find engine",
          "slug": "search-engine-or-find-engine",
          "description": "Search engines rule the world.  Online and  in the real world via all kinds of devices from phones to fridges.  It is time for something in between.  Findoborg is all about Find engines.  We take information and allow you to work for it instead of trying to guess your intent."
        }
      ]
    }
  }
}```

Any help would be great.
travis-r6s commented 3 years ago

I'm afraid I'm not sure how that code fits with this plugin? Checkout the readme if you want to know how to add a collection to the FlexSearch index...