← back to Dw Sarah Rowland Searchfix

probe.mjs

48 lines

// READ-ONLY probe: confirm token + pull the whole collection from LIVE Shopify.
// Reports each product's title, tags, and whether "Sarah Rowland" is already in a
// search-indexed field (title/tags) — i.e. which products are currently invisible.
import { gql, HANDLE } from './lib.mjs';

const Q = `
query($handle:String!, $cursor:String){
  collectionByHandle(handle:$handle){
    id title
    products(first:100, after:$cursor){
      pageInfo{ hasNextPage endCursor }
      nodes{
        id title vendor productType tags
        metafield(namespace:"custom", key:"designer"){ value }
      }
    }
  }
}`;

const all = [];
let cursor = null, coll = null;
do {
  const d = await gql(Q, { handle: HANDLE, cursor });
  coll = d.collectionByHandle;
  if (!coll) { console.error('Collection not found for handle', HANDLE); process.exit(1); }
  all.push(...coll.products.nodes);
  cursor = coll.products.pageInfo.hasNextPage ? coll.products.pageInfo.endCursor : null;
} while (cursor);

const has = (p) => /sarah\s*rowland/i.test(p.title) || p.tags.some(t => /sarah\s*rowland/i.test(t));
const visible = all.filter(has);
const invisible = all.filter(p => !has(p));
const alreadyTagged = all.filter(p => p.tags.some(t => /sarah\s*rowland/i.test(t)));
const hasMeta = all.filter(p => p.metafield && /sarah\s*rowland/i.test(p.metafield.value || ''));

console.log(`Collection: ${coll.title} (${coll.id})`);
console.log(`Total products:            ${all.length}`);
console.log(`Search-visible (title/tag): ${visible.length}`);
console.log(`Search-INVISIBLE:           ${invisible.length}`);
console.log(`Already carry SR tag:       ${alreadyTagged.length}`);
console.log(`Already have custom.designer=SR: ${hasMeta.length}`);
console.log(`\nSample invisible titles:`);
invisible.slice(0, 8).forEach(p => console.log('  -', p.title, '|', JSON.stringify(p.tags.slice(0,3))));

fsWrite(all);
import fs from 'node:fs';
function fsWrite(a){ fs.writeFileSync(new URL('./products.json', import.meta.url), JSON.stringify(a, null, 2)); }