@@ -103,33 +103,54 @@ class DatabaseSeedingService {
103103 Future <void > _ensureIndexes () async {
104104 _log.info ('Ensuring database indexes exist...' );
105105 try {
106- // Text index for searching headlines by title
106+ /// Text index for searching headlines by title.
107+ /// This index supports efficient full-text search queries on the 'title' field
108+ /// of headline documents, crucial for the main search functionality.
107109 await _db
108110 .collection ('headlines' )
109111 .createIndex (keys: {'title' : 'text' }, name: 'headlines_text_index' );
110112
111- // Text index for searching topics by name
113+ /// Text index for searching topics by name.
114+ /// This index enables efficient full-text search on the 'name' field of
115+ /// topic documents, used for searching topics.
112116 await _db
113117 .collection ('topics' )
114118 .createIndex (keys: {'name' : 'text' }, name: 'topics_text_index' );
115119
116- // Text index for searching sources by name
120+ /// Text index for searching sources by name.
121+ /// This index facilitates efficient full-text search on the 'name' field of
122+ /// source documents, used for searching sources.
117123 await _db
118124 .collection ('sources' )
119125 .createIndex (keys: {'name' : 'text' }, name: 'sources_text_index' );
120126
121- // Index for searching countries by name (case-insensitive friendly)
127+ /// Index for searching countries by name.
128+ /// This index supports efficient queries and sorting on the 'name' field
129+ /// of country documents, particularly for direct country searches.
122130 await _db
123131 .collection ('countries' )
124132 .createIndex (keys: {'name' : 1 }, name: 'countries_name_index' );
125133
126- // Indexes for country aggregation queries
134+ /// Indexes for country aggregation queries.
135+ /// This compound index optimizes queries that filter by 'status' and
136+ /// group by 'eventCountry.id' in the headlines collection.
127137 await _db
128138 .collection ('headlines' )
129139 .createIndex (
130140 keys: {'status' : 1 , 'eventCountry.id' : 1 },
131141 name: 'status_eventCountry_index' ,
132142 );
143+ /// Index for efficient filtering of headlines by the name of the
144+ /// associated event country. This is crucial for the country search
145+ /// functionality when filtering by 'eventCountry' usage.
146+ await _db
147+ .collection ('headlines' )
148+ .createIndex (
149+ keys: {'eventCountry.name' : 1 },
150+ name: 'eventCountry_name_index' ,
151+ );
152+ /// This compound index optimizes queries that filter by 'status' and
153+ /// group by 'headquarters.id' in the sources collection.
133154 await _db
134155 .collection ('sources' )
135156 .createIndex (
0 commit comments