Overview

I tried out Next.js for Drupal.

https://next-drupal.org/

By following the “Get Started” guide, I was able to integrate Next.js with Drupal.

https://next-drupal.org/learn/quick-start

Additionally, the following article introduces an implementation example of faceted search.

https://next-drupal.org/guides/search-api

This article focuses on notes about implementing the latter faceted search.

Search API

Create a Server and index as follows.

The official site provides the following reference.

https://www.drupal.org/docs/contributed-modules/search-api

For Japanese sites, the following is a useful reference.

https://www.acquia.com/jp/blog/introduction-to-search-api-1

Creating a Server

Creating an Index

This time, an index called test_index_20230417 is created.

Furthermore, title was added as a field.

After that, indexing is performed.

JSON:API

After completing the above, clear the cache.

/admin/config/development/performance

Then, the endpoint becomes accessible from the following URL.

/jsonapi/index/test_index_20230417

Search results can be filtered using query parameters as follows.

/jsonapi/index/test_index_20230417?filter[title]=更新したタイトル

{."}".j,d.s""}a{ovmtnee"}a"""}"artl"til,apsai"}:ydi"}t"""""""""""""ii"nsp"nstddlrrstccpsdr"o:ke"[e:ke"rrraeetirhrtee:nslh"slhiuunvvateaoifv"{"fr:""frbppgiitlanmcai{::"e8:"euaacssuetgokus:f"2:ftlloiis"eetyli"{"na{"e__doo":dde"to1{:o3{:siienn:""":_n.d4"nn"__":::l_0"ec":tt:tltfat"h-3heeior""fanr,t-5t{rr"mgu22algats-tnnee"e00lscnpefpaans:,22seos:r1sll"t33e,dl/vb:__,an--,ea/i7/__mu00"tjc-/nvpl"44:ise4xii"l,--oo"9xdd:,11tnn,ex""12r_ab/::"TTuap-j200efi8s45028,f.1o,02::eoan7301crca5-99tg-p,0::e/fi430df1/-50"o5n1++:rdo200m0dT00tade0::rte/800u/as:00e1ce1"",.2r9,,02v:/ci0""c0,e+/0802:a0304"c,35-f1b7-49eb-81ac-f15d0deac22c?resourceVersion=id%3A5075"

Facets

Access the following.

/admin/config/search/facets

Click “Add facet” and select the index created earlier.

On the next screen, select “JSON:API Search API” for the Widget.

Then, clear the cache and access the endpoint again.

/jsonapi/index/test_index_20230417

As shown below, a facets item is added. This can be used to implement faceted search from the frontend.

{}"}""}"}j,dm,ls""}ae""]i"}ovmttcfnsnee"}aaoa{}ke"artl""ucslhpsai"}::ne""""]"frii"nsttilpt:"e"o:ke"[{"sdaae{}{}:f:nslh.:""btr,{""{"fr.::ehm""}""}{:{::"e.2l"suvuv:f],["":"ra""""ra""""""{",t::llvlacllvlach1{:i""uaaco"uaacot.t"t[:elbtu:elbtut0"lTisueinsueinp"heit""elvt""elvts,t_tlh:""e"h:""e":t2let::":t::":/p0e_t{:t{:/:2"2p""1p""1x/3,0sfsfx/02:a:axj43/l/l/s10/s/sjo74xexesn"1x,x,oa,7xxnp"//ai,jj""p.ss,,iooo/rnniga""an/p,,pdfiieo//xrii/mnntaddetees/xxt1//_.tti0een/ssd"tte__xii_nn2dd0ee2xx3__022400122733"00441177??ffiilltteerr%%55BBttiittllee__2200223300441177%%55DD==%%EE56%%B99B%%BB34%%EE86%%B936%%8B00%%EE83%%A8D1%%B927%%EE33%%8831%%897F%%EE33%%8822%%BB8F%%EE33%%8822%%BAF4%%EE33%%8833%%A8B8%%EE33%%8823%%AA2B%"E,3%83%BC%E3%82%AB%E3%82%A4%E3%83%96",

Summary

An integration example with Next.js has its source code published in the following repository.

https://github.com/chapter-three/next-drupal/blob/main/examples/example-search-api/pages/advanced.tsx

By replacing the index and fields with those I configured myself, I was able to create a search page like the following demo page.

https://example-search-api.next-drupal.org/advanced

I hope this serves as a useful reference for faceted search using the JSON:API module.