@@ -725,15 +725,6 @@ function SearchRecord(ctx::HTMLContext, navnode; fragment = "", title = nothing,
725725 )
726726end
727727
728- function SearchRecord (ctx:: HTMLContext , navnode, node:: Node , element:: Documenter.AnchoredHeader )
729- a = element. anchor
730- return SearchRecord (
731- ctx, navnode;
732- fragment = Documenter. anchor_fragment (a),
733- title = mdflatten (node), # AnchoredHeader has Heading as single child
734- category = " section"
735- )
736- end
737728
738729function SearchRecord (ctx, navnode, node:: Node , :: MarkdownAST.AbstractElement )
739730 return SearchRecord (ctx, navnode; text = mdflatten (node))
@@ -745,12 +736,62 @@ const _SEARCHRECORD_IGNORED_BLOCK_TYPES = Union{
745736 Documenter. DocsNodesBlock,
746737 Documenter. SetupNode,
747738}
748- function searchrecord (ctx:: HTMLContext , navnode:: Documenter.NavNode , node:: Node )
749- # Skip indexing special at-blocks
750- if node. element isa _SEARCHRECORD_IGNORED_BLOCK_TYPES
751- return nothing
739+
740+ # Content segment for grouping content by sections
741+ struct ContentSegment
742+ section_header:: Union{Node, Nothing}
743+ content_nodes:: Vector{Node} # Content nodes belonging to this section
744+ end
745+
746+ # Segment page content by sections for improved search indexing
747+ function segment_page_by_sections (page_mdast:: Node )
748+ segments = ContentSegment[]
749+ current = ContentSegment (nothing , Node[])
750+
751+ for node in page_mdast. children
752+ if node. element isa Documenter. AnchoredHeader
753+ # Save previous segment if it has content or a header
754+ if ! isempty (current. content_nodes) || current. section_header != = nothing
755+ push! (segments, current)
756+ end
757+ # Start new section
758+ current = ContentSegment (node, Node[])
759+ else
760+ # Skip nodes that shouldn't be indexed
761+ if ! (node. element isa _SEARCHRECORD_IGNORED_BLOCK_TYPES)
762+ push! (current. content_nodes, node)
763+ end
764+ end
765+ end
766+
767+ # Add final segment
768+ if ! isempty (current. content_nodes) || current. section_header != = nothing
769+ push! (segments, current)
770+ end
771+
772+ return segments
773+ end
774+
775+ # Create search record for a content segment
776+ function searchrecord (ctx:: HTMLContext , navnode:: Documenter.NavNode , segment:: ContentSegment )
777+ text = join ([mdflatten (node) for node in segment. content_nodes], " \n\n " )
778+
779+ if segment. section_header === nothing
780+ title = nothing
781+ fragment = " "
782+ else
783+ a = segment. section_header. element. anchor
784+ title = mdflatten (segment. section_header)
785+ fragment = Documenter. anchor_fragment (a)
752786 end
753- return SearchRecord (ctx, navnode, node, node. element)
787+
788+ return SearchRecord (
789+ ctx, navnode;
790+ fragment,
791+ title,
792+ category = " section" ,
793+ text
794+ )
754795end
755796
756797function JSON. lower (rec:: SearchRecord )
@@ -1749,11 +1790,17 @@ end
17491790
17501791function domify (dctx:: DCtx )
17511792 ctx, navnode = dctx. ctx, dctx. navnode
1752- return map (getpage (ctx, navnode). mdast. children) do node
1753- rec = searchrecord (ctx, navnode, node)
1754- if ! isnothing (rec)
1755- push! (ctx. search_index, rec)
1756- end
1793+ page_mdast = getpage (ctx, navnode). mdast
1794+
1795+ # Generate search index using custom segmentation, with pages merged together
1796+ segments = segment_page_by_sections (page_mdast)
1797+ for segment in segments
1798+ search_record = searchrecord (ctx, navnode, segment)
1799+ push! (ctx. search_index, search_record)
1800+ end
1801+
1802+ # Generate HTML as before - process each child node individually
1803+ return map (page_mdast. children) do node
17571804 domify (dctx, node, node. element)
17581805 end
17591806end
0 commit comments