@@ -398,9 +398,8 @@ function initializeMeilisearchIntegration() {
398398 indicatorEl . innerHTML = 'Searching…' ;
399399 resultsContainer . appendChild ( indicatorEl ) ;
400400
401- // Build search options
402- const searchOptions = {
403- limit : 25 ,
401+ // Build base search options
402+ const baseSearchOptions = {
404403 attributesToHighlight : [ 'hierarchy_lvl1' , 'hierarchy_lvl2' , 'hierarchy_lvl3' , 'hierarchy_lvl4' , 'hierarchy_lvl5' , 'content' ] ,
405404 attributesToCrop : [ 'content' ] ,
406405 cropLength : 100 ,
@@ -410,19 +409,52 @@ function initializeMeilisearchIntegration() {
410409 }
411410 } ;
412411
413- // Add filter if sections are selected
414- if ( activeFilters . length > 0 ) {
415- searchOptions . filter = activeFilters . map ( section => `section = "${ section } "` ) . join ( ' OR ' ) ;
416- }
412+ // Create federated multi-search queries
413+ const multiSearchQueries = [
414+ {
415+ indexUid : MEILISEARCH_INDEX ,
416+ q : query ,
417+ // Lower weight for error code results
418+ filter : activeFilters . length > 0
419+ ? `(${ activeFilters . map ( section => `section = "${ section } "` ) . join ( ' OR ' ) } ) AND (hierarchy_lvl0 = "Errors" OR hierarchy_lvl1 = "Error codes")`
420+ : `hierarchy_lvl0 = "Errors" OR hierarchy_lvl1 = "Error codes"` ,
421+ federationOptions : {
422+ weight : 0.7
423+ } ,
424+ ...baseSearchOptions
425+ } ,
426+ {
427+ indexUid : MEILISEARCH_INDEX ,
428+ q : query ,
429+ // Higher weight for non-error code results
430+ filter : activeFilters . length > 0
431+ ? `(${ activeFilters . map ( section => `section = "${ section } "` ) . join ( ' OR ' ) } ) AND NOT (hierarchy_lvl0 = "Errors" OR hierarchy_lvl1 = "Error codes")`
432+ : `NOT (hierarchy_lvl0 = "Errors" OR hierarchy_lvl1 = "Error codes")` ,
433+ federationOptions : {
434+ weight : 1.0
435+ } ,
436+ ...baseSearchOptions
437+ }
438+ ] ;
417439
418- // Perform search
419- index . search ( query , searchOptions )
440+ // Perform federated multi-search
441+ const multiSearchRequest = {
442+ federation : {
443+ limit : 25
444+ } ,
445+ queries : multiSearchQueries
446+ } ;
447+
448+ client . multiSearch ( multiSearchRequest )
420449 . then ( response => {
421450 resultsContainer . innerHTML = '' ;
422451
423452 const filterContainer = document . getElementById ( 'meilisearch-filter-container' ) ;
424453
425- if ( response . hits . length === 0 ) {
454+ // Handle federated multi-search response
455+ const allHits = response . hits || [ ] ;
456+
457+ if ( allHits . length === 0 ) {
426458 if ( filterContainer ) filterContainer . style . display = 'none' ;
427459 const noResultsEl = document . createElement ( 'div' ) ;
428460 noResultsEl . className = 'meilisearch-modal__indicator' ;
@@ -436,7 +468,7 @@ function initializeMeilisearchIntegration() {
436468
437469 // Group results by category if available
438470 const grouped = { } ;
439- response . hits . forEach ( hit => {
471+ allHits . forEach ( hit => {
440472 const category = hit . hierarchy_lvl0 || 'General' ;
441473 if ( ! grouped [ category ] ) {
442474 grouped [ category ] = [ ] ;
0 commit comments