travis-r6s / gridsome-plugin-flexsearch

Add lightning fast search to Gridsome with FlexSearch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Full Query with Shopify Source Plugin

chrispreisler opened this issue · comments

commented

Hey guys,

I want to use the flexsearch plugin with a Shopify website. I also use your Shopify Source Plugin for queries to Shopify.

I would like to search through the products. Unfortunately it doesn't creates the full query for one product. Here is an example of one search item from the flexsearch.json:

    "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzQ0NjMzMzI4NTE4NTE=": {
      "index": "Product",
      "id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzQ0NjMzMzI4NTE4NTE=",
      "path": "/product/lodenmantel-wolle-grun-l/",
      "variants": "[{\"availableForSale\":true,\"compareAtPrice\":null,\"id\":\"Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8zMTg5NDA2NjgyMzMwNw==\",\"image\":{\"typeName\":\"ShopifyImage\",\"id\":\"Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTM5NzY0MDQ4ODU2NDM=\"},\"price\":{\"typeName\":\"ShopifyProduct_Variants_Price\",\"id\":\"AT-1lQ_5pdlekGFPa6Kq8\"},\"selectedOptions\":[{\"name\":\"Size\",\"value\":\"L\"},{\"name\":\"Color\",\"value\":\"Grün\"}],\"sku\":\"MA-028-1911\",\"title\":\"L / Grün\",\"weight\":1400,\"weightUnit\":\"KILOGRAMS\"}]",
      "priceRange": {
        "minVariantPrice": {
          "typeName": "ShopifyProduct_PriceRange_MinVariantPrice",
          "id": "i-y_HaiYoQ07A-PGvLWdE"
        },
        "maxVariantPrice": {
          "typeName": "ShopifyProduct_PriceRange_MaxVariantPrice",
          "id": "aBSGIuzc-kAnC9uCiC9dr"
        }
      },
      "images": "[{\"typeName\":\"ShopifyImage\",\"id\":\"Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTM5NzY0MDQ4ODU2NDM=\"},{\"typeName\":\"ShopifyImage\",\"id\":\"Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTM5NzY0MDQ5MTg0MTE=\"},{\"typeName\":\"ShopifyImage\",\"id\":\"Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTM5NzY0MDQ5NTExNzk=\"},{\"typeName\":\"ShopifyImage\",\"id\":\"Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTM5NzY0MDQ5ODM5NDc=\"},{\"typeName\":\"ShopifyImage\",\"id\":\"Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTM5NzY0MDUwMTY3MTU=\"}]",
      "description": "Ein Lodenmantel zum Verlieben! Geschmückt ist der Vintage Mantel mit karierten Highlights und Holzknöpfen.",
      "handle": "lodenmantel-wolle-grun-l",
      "title": "Lodenmantel Wolle Grün"
    }

As you can see, it doesn't fetch the details of the images or the prices. Also I don't understand, why it esacpes the " in some parts of the json.

Here ist the part in my gridsome.config.js:

    {
      use: "gridsome-plugin-flexsearch",
      options: {
        collections: [
          {
            typeName: "ShopifyProduct",
            indexName: "Product",
            fields: [
              "title",
              "handle",
              "description",
              "images",
              "priceRange",
              "variants"
            ]
          }
        ],
        searchFields: ["title"]
      }
    }

Thank you very much for your help in advance.

Best regards
Chris

Sorry - I'm not sure I understand your issue - the price and image fields do seem to be included in the JSON? Or were you trying to search through those?

Ah, just looked at the result properly - I will take a look at this.

It also escapes some characters as it has been JSON.stringified() - Flexsearch will handle this.

commented

Great thank you very much. Sorry for maybe not describing it perfectly.

@chrispreisler Sorry for the delay on this - still trying to think of a way to solve this, as I need to check if a record (i.e. the linked images) is a collection type, then fetch that specific record from its respective store if so.

commented

No problem. Thanks for looking into that. 👍

Hey @chrispreisler,

Just published 0.1.6, which should add support for linked fields - would you be able to try this out, and check it works for you?

commented

Thank you very much. Will look into that next week.

commented

Hey @thetre97 ,

I tested it right now and for images it is working perfect. Unfortunately for price it is not working.

Is it possible to also create the connection to the price in the query?

"priceRange":{
      "minVariantPrice":{
         "typeName":"ShopifyPrice",
         "id":"KUi-afKw90pKkzNsH-PE1"
      },
      "maxVariantPrice":{
         "typeName":"ShopifyPrice",
         "id":"dJz1tUn8hKaEBobGe856m"
      }
   },

Thanks again for your help in advance.

Best regards
Chris

Ah yes, I forgot about doubly nested fields - I will work on that.

Would this fix an issue with a collection reference being pulled in?

@arincon9 If it is more than one object deep, yes.

Hey @chrispreisler @arincon9 - just released 0.1.19. Would you be able to try that, and check it fixes your problem?

@thetre97 This release actually breaks my build. I get the following error:

RangeError: Maximum call stack size exceeded

at Function.isArray (<anonymous>)
at parseObject (.../node_modules/gridsome-plugin-flexsearch/gridsome.server.js:40:15)

@arincon9 Does your array field have relations in it? I.e. something like this:

// Product type
{
   id: 1,
   title: 'some-product',
   collections: [{ title: 'some', product: { id: 1, title: 'some-product' } }]
}

Don't suppose you would be able to show an example of your config, and your data?

@thetre97 I have a workout collection with a trainer id field and a trainer reference as such:
workoutCollection.addReference('trainer', 'Trainers')

commented

@thetre97 Thank you so much. For me it is now working perfect.

@arincon9 And does the Trainer type have the reverse relation or workouts?
I'm not sure why it would be throwing this error, but will keep looking into it.