Home > Back-end >  The Prismic fulltext predicate keeps giving me errors about unexpected fields when I Use it to try t
The Prismic fulltext predicate keeps giving me errors about unexpected fields when I Use it to try t

Time:03-31

I am trying to query with the Prismic predicate.fulltext using Vuejs this is the first time am using the predicate but the documentation about what the fulltext predicate needs seems to be confusing. Here is my code.

async searchByQuery(query) {
    const fullTextResult = await this.$prismic.client.get({
      predicates: this.$prismic.predicate.not("articles.article_title", query),
    });
    console.log(fullTextResult);
  },

where articles is my custom type and article_title is a field in my custom type. That is what I understood from the documentation on how to do it but then I get an unexpected error

Prismic Fulltext Predicate error

I would like a clarification on why this does not work and what the documentation really mean. Am Using Vue3 by the way and that means am using the updated prismicio/client

CodePudding user response:

You are pretty close!

Using Vue 3, you're looking at something like that:

export default {
  methods: {
    async searchByQuery(query) {
      const fullTextResult = await this.$prismic.client.get({
        predicates:
          this.$prismic.predicate.fulltext(
            "my.articles.article_title",
            query
          )
      });

      console.log(fullTextResult);
    }
  }
};

Basically, you need to prefix articles.article_title with my. to indicate it's a field on one of your document type, and change the predicate you're using to precidate.fulltext instead of predicate.not (assuming you want to run a fulltext search)

Let me know if that helps :)

  • Related