-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
150,747 additions
and
160 deletions.
There are no files selected for viewing
27 changes: 0 additions & 27 deletions
27
starters/shopify-meilisearch/app/actions/collection.actions.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
84 changes: 0 additions & 84 deletions
84
starters/shopify-meilisearch/app/actions/product.actions.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,90 @@ | ||
import { unstable_cache } from "next/cache" | ||
|
||
import { env } from "env.mjs" | ||
|
||
import { getDemoProductReviews, getDemoSingleProduct, isDemoMode } from "utils/demo-utils" | ||
import { notifyOptIn } from "utils/opt-in" | ||
|
||
import { meilisearch as searchClient } from "lib/meilisearch" | ||
import { ComparisonOperators, FilterBuilder } from "lib/meilisearch/filter-builder" | ||
|
||
import type { Review } from "lib/reviews/types" | ||
|
||
import type { CommerceProduct } from "types" | ||
|
||
export const meilisearch: ReturnType<typeof searchClient> = searchClient({ | ||
host: env.MEILISEARCH_HOST || "", | ||
adminApiKey: env.MEILISEARCH_ADMIN_KEY || "", | ||
}) | ||
|
||
export const searchProducts = unstable_cache( | ||
async (query: string, limit: number = 4) => { | ||
if (isDemoMode()) | ||
return { | ||
hits: [], | ||
hasMore: false, | ||
} | ||
|
||
const { hits, estimatedTotalHits } = await meilisearch.searchDocuments<CommerceProduct>({ | ||
indexName: env.MEILISEARCH_PRODUCTS_INDEX, | ||
query, | ||
options: { | ||
limit, | ||
attributesToRetrieve: ["id", "handle", "title", "featuredImage", "images", "variants"], | ||
}, | ||
}) | ||
|
||
return { hits, hasMore: estimatedTotalHits > limit } | ||
}, | ||
["autocomplete-search"], | ||
{ revalidate: 3600 } | ||
) | ||
|
||
export const getProduct = unstable_cache( | ||
async (handle: string) => { | ||
if (isDemoMode()) return getDemoSingleProduct(handle) | ||
|
||
const { results } = await meilisearch.getDocuments<CommerceProduct>({ | ||
indexName: env.MEILISEARCH_PRODUCTS_INDEX, | ||
options: { | ||
filter: new FilterBuilder().where("handle", ComparisonOperators.Equal, handle).build(), | ||
limit: 1, | ||
}, | ||
}) | ||
|
||
return results.find(Boolean) || null | ||
}, | ||
["product-by-handle"], | ||
{ revalidate: 3600 } | ||
) | ||
|
||
export const getProductReviews = unstable_cache( | ||
async (handle: string, { page = 1, limit = 10 } = { page: 1, limit: 10 }) => { | ||
if (isDemoMode()) return getDemoProductReviews() | ||
|
||
if (!env.MEILISEARCH_REVIEWS_INDEX) { | ||
notifyOptIn({ feature: "reviews", source: "product.actions.ts" }) | ||
return { reviews: [], total: 0 } | ||
} | ||
|
||
const { results, total } = await meilisearch.getDocuments<Review>({ | ||
indexName: env.MEILISEARCH_REVIEWS_INDEX, | ||
options: { | ||
filter: new FilterBuilder() | ||
.where("product_handle", ComparisonOperators.Equal, handle) | ||
.and() | ||
.where("published", ComparisonOperators.Equal, "true") | ||
.and() | ||
.where("hidden", ComparisonOperators.Equal, "false") | ||
.build(), | ||
limit, | ||
offset: (page - 1) * limit, | ||
fields: ["body", "rating", "verified", "reviewer", "published", "created_at", "hidden", "featured"], | ||
}, | ||
}) | ||
|
||
return { reviews: results.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime()), total } | ||
}, | ||
["product-reviews-by-handle"], | ||
{ revalidate: 3600 } | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130,816 changes: 130,815 additions & 1 deletion
130,816
starters/shopify-meilisearch/lib/shopify/types/admin/admin-2024-01.schema.json
Large diffs are not rendered by default.
Oops, something went wrong.
19,768 changes: 19,767 additions & 1 deletion
19,768
starters/shopify-meilisearch/lib/shopify/types/storefront-2024-01.schema.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.