﻿//+------------------------------------------------------------------+
//|                                                 SearchEngine.mqh |
//|                                  Copyright 2025, MetaQuotes Ltd. |
//|                          https://www.mql5.com/en/users/lynnchris |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, MetaQuotes Ltd."
#property link      "https://www.mql5.com/en/users/lynnchris"
#property version   "1.00"

#ifndef _SEARCH_ENGINE_MQH
#define _SEARCH_ENGINE_MQH

#include "IndicatorCatalog.mqh"

//+------------------------------------------------------------------+
//| Search engine – filters indicators by name (case-insensitive)    |
//+------------------------------------------------------------------+
class CSearchEngine
  {
private:
   CIndicatorCatalog   m_catalog;
public:
                     CSearchEngine() {}
                    ~CSearchEngine() {}
   void               Filter(string searchText, SIndicatorInfo &outResults[]);
  };

//+------------------------------------------------------------------+
//| Filters the catalog by substring match in the indicator name     |
//+------------------------------------------------------------------+
void CSearchEngine::Filter(string searchText, SIndicatorInfo &outResults[])
  {
//--- Clear the output array
   ArrayResize(outResults, 0);
//--- If search text is empty, return no results
   if(searchText == "")
      return;

//--- Convert search text to lowercase for case‑insensitive comparison
   string lowerSearch = searchText;
   StringToLower(lowerSearch);

   int total = m_catalog.Count();
//--- Loop through all indicators in the catalog
   for(int i = 0; i < total; i++)
     {
      SIndicatorInfo info;
      if(!m_catalog.GetInfo(i, info))
         continue;

      string lowerName = info.name;
      StringToLower(lowerName);

      //--- If the indicator name contains the search string, add it to results
      if(StringFind(lowerName, lowerSearch) != -1)
        {
         int newSize = ArraySize(outResults);
         ArrayResize(outResults, newSize + 1);
         outResults[newSize] = info;
        }
     }
  }

#endif // _SEARCH_ENGINE_MQH
//+------------------------------------------------------------------+