Search API Not working

Solved
vishak-creo
Tourist
3 0 0

I'm using the Query as below.

{
  products(first: 8 ,query:"title: ${productSearchTerm?.isEmpty == true ? "*" : '*$productSearchTerm' + '*'}, variants.price:>0", after: ${cursor.isEmpty ? null : '''"$cursor"'''}, , sortKey: TITLE) {
      pageInfo{
        hasNextPage
        hasPreviousPage
      }
      allProducts : edges{
        cursor
        productDetails : node{
          id
          onlineStoreUrl
          handle
          title
        	description
          descriptionHtml
          variantsResult: variants(first:8){
      			allVariants: edges{
        		variantDetails: node{
            title
            availableForSale
            id
            presentmentPricesResult: presentmentPrices(first:1){
              allPresentmentPrices: edges{
                presentmentPricesDetail: node{
                   presentmentActualPrice: price{
                    amount
                    currencyCode
                  }
                  presentmentComparePrice: compareAtPrice{
                    amount
                    currencyCode
                  }
                }
              }
            }
        		actualPrice: price
            imageDetails: image{
              originalSrc
            }
            weight
            weightUnit
            requiresShipping
       	 }
      }
    }
          imagesResult: images(first:6){
            allImages: edges{
              imageDetails: node{
                originalSrc
              }
            }
          }
          priceRange{
            maxVariantPrice{
              amount
              currencyCode
            }
            minVariantPrice{
              amount
              currencyCode
            }
          }
        }
      }
    }
}

 But No matter what I pass for title, I'm getting the Empty List. When Empty String is passed, I get 8 Products from Latest Arrivals Category.

0 Likes
garyrgilbert
Explorer
55 6 13

 

Hi there... Its a simple fix. Remove the space after the colon.

from...

"title: ${pro

 to

"title:${pro

 

The search is looking for anything that starts with a space..

 

To help with debugging I would also suggest not to try to have logic like you have but to perform all logic prior to passing the seach term, same with your cursor.

 

Cheers,

 

Gary

 

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
vishak-creo
Tourist
3 0 0

Hi,

I tried this. Still the list is coming empty.

When the search query is empty  

 

products(first: 8 ,query:"variants.price:>0", after:null, sortKey: TITLE)

 

 I'm getting all products sorted by Title which is as expected. 

And When I enter some search query, after I made the changes you suggested, this is how it looks now

 

products(first: 8 ,query:"title:flutter*, variants.price:>0", after:null, sortKey: TITLE)

 

Still no results.

Have tried *flutter*, flutter, and also tried removing the `after` parameter when it is null. 
Here flutter is full name of a product. 

I don't understand what I'm missing or what I'm doing wrong here.

0 Likes
garyrgilbert
Explorer
55 6 13

This is an accepted solution.

 

The next problem is this:

products(first: 8 ,query:"title:flutter*, variants.price:>0", after:null, sortKey: TITLE)

 

What are you doing with the comma after "flutter*" is that suppose to be and "AND"?

In other words: "give me the first 8 products with the title that starts with flutter AND the variant price is > 0"?

If so then try this:

products(first: 8 ,query:"title:flutter* AND price:>0", after:null, sortKey: TITLE)

 

For my test store I used this modified version of your Query where I know that only one variant has a title that starts with 5 and price less than 49:

{
  products(first: 8 ,query:"title:5* AND price:<49", after: null, sortKey: TITLE) {
      pageInfo{
        hasNextPage
        hasPreviousPage
      }
      allProducts : edges{
        cursor
        productDetails : node{
          id
          onlineStoreUrl
          handle
          title
        	description
          descriptionHtml
          variantsResult: variants(first:8){
      			edges{
        		variantDetails: node{
            title
            availableForSale
            id
            presentmentPricesResult: presentmentPrices(first:1){
              allPresentmentPrices: edges{
                presentmentPricesDetail: node{
                   presentmentActualPrice: price{
                    amount
                    currencyCode
                  }
                  presentmentComparePrice: compareAtPrice{
                    amount
                    currencyCode
                  }
                }
              }
            }
        		actualPrice: price
            imageDetails: image{
              originalSrc
            }
            weight
            weightUnit
            requiresShipping
       	 }
      }
    }
          imagesResult: images(first:6){
            allImages: edges{
              imageDetails: node{
                originalSrc
              }
            }
          }
          priceRange{
            maxVariantPrice{
              amount
              currencyCode
            }
            minVariantPrice{
              amount
              currencyCode
            }
          }
        }
      }
    }
}

 

Hope this helps

Cheers

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
vishak-creo
Tourist
3 0 0

Hey thanks Gary. Worked perfectly.

0 Likes