Preparing File with Synonyms

BI search enables the user to count synonyms. To enable this feature, prepare the synonyms.txt file copied on setting up of Solr instances. Apache Solr uses one common file synonyms.txt containing a list of synonyms in all languages.

The synonyms.txt file consists of a number of strings. Each group of synonyms is specified in a single string. Words or word combinations are separated with a comma. To enable search by various word forms, Apache Solr uses special search algorithms, to enable their work, synonyms must be entered without affixes. You can use two methods to prepare words to be used in the search by Apache Solr:

  1. Use Apache Solr analyzer:

  2. Use the Fore core that is used to work with Apache Solr: the following function can be used to analyze and get required combination of synonyms:
    Function AnalysisString(Phrase: String): Array;
    Const
        CoreURL = "http://localhost:8080/solr-4.4.0/SourceData_ru1";
    Var
        MB: IMetabase;
        SearchFactory: ISearchEngineServiceFactory;
        SolrService: ISolrSearchEngineService;
        Core: ISolrSearchEngineCore;
        SolrOp: ISolrOperations;
        Result: Array Of Variant;
    Begin
        MB := MetabaseClass.Active;
        //BI search mechanism parameters
        SearchFactory := New SearchEngineServiceFactory.Create;
        SolrService := SearchFactory.CreateSearchEngine(MB) As ISolrSearchEngineService;
        Core := SolrService.Cores.Add(CoreURL, SearchEngineTargetType.SourceData, LocaleCodeID.Russian);
        //Object used to work with Apache Solr
        SolrOp := New SolrOperations.Create;
        //Analysis of synonyms
        Result := SolrOp.GetPhraseAnalysisByFieldType(Core, "synonyms_transformer", Phrase) As Array;
        //Return result
        Return Result;
    End Function AnalysisString;

A set of synonyms is passed as a function input parameter, the output is an array of processed words. If you appropriately develop the code, it will be possible to save words from the array directly to the synonyms.txt file or to other storage place.

See also:

Installing and Setting Up Software