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:
Use Apache Solr analyzer:
Select the required instance in the page of installed Apache Solr and go to the Analysis tab. The created link will look as follows: http://localhost:8080/solr-4.4.0#/SourceData_ru1/analysis.
Select the synonyms_transformer type in the Analyse Fieldname / FieldType drop-down list.
Specify the required combination of synonyms in the Field Value (Index) box, for example, "GDP, Gross Domestic Product", and click the Analyse Values button.
Results of processed data by various filters are output to the page (the Verbose Output checkbox can be deselected to display only text obtained after data processing).
The last string is the set of synonyms that must be saved to the synonyms.txt file. For example, the word combination saved to the file for the specified above word combination "GDP, Gross Domestic Product" will be "gdp, gr. dom. prod.".
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: