Indexing

After getting access to the object that executes indexing, prepare a context with indexing settings. To create a context, call the IImportExecutor.CreateContext method. Depending on what will be indexed (data source structures or repository object metadata), cast method result to one of two interfaces: ISourceDataImportContext and IMbObjectsImportContext. To determine indexing execution parameters, the result of the IImportExecutor.CreateContext method can also be cast to the ISolrImportContext interface.

IMPORTANT. Taking into account the Fore language implementation features, it cannot be used to create a code for objects indexing. All the next examples are implemented oin the Fore.NET language.

Public Shared Sub Main(Params: StartParams);
Var
    //...
    MB: IMetabase;
    SharedParams: ISharedParams;
    SearchEngine: ISolrSearchEngineService;
    SearchSchema: ISolrSearchEngineSchema;
    ImportExecutor: IImportExecutor;
    SourceContext: ISourceDataImportContext;
    MbObjContext: IMbObjectsImportContext;
    Locales: Array = New Integer[1] = [LocaleCodeID.lcidRussian As Integer];
    //...
Begin
    //...
    MB := Params.Metabase;
    //Search and indexing parameters specified for repository
    SharedParams := MB.SpecialObject[MetabaseSpecialObject.msoSharedParams].Bind() As ISharedParams;
    SearchEngine := SharedParams.SearchEngine As ISolrSearchEngineService;
    SearchSchema := SearchEngine.SearchEngineSchema As ISolrSearchEngineSchema;
    //To index data sources
    ImportExecutor := SearchSchema.ImportExecutor[SearchEngineTargetType.settSourceData];
    SourceContext := ImportExecutor.CreateContext() As ISourceDataImportContext;
    //...
    //To index repository object metadata
    ImportExecutor := SearchSchema.ImportExecutor[SearchEngineTargetType.settMbObject];
    MbObjContext := ImportExecutor.CreateContext() As IMbObjectsImportContext;
    //...
    //Determine indexing execution parameters
    (SourceContext As ISolrImportContext).CleanType := SolrImportCleanType.sictSpecified;
    (SourceContext As ISolrImportContext).Locales := Locales;
    (MbObjContext As ISolrImportContext).CleanType := SolrImportCleanType.sictNone;
    (MbObjContext As ISolrImportContext).Locales := Locales;
    //...
End Sub;

Data Source Indexing

Indexed objects can be set in two ways: in the ContainerKeys property determine a key array of container objects where data sources are stored or add required sources to the SourceInfos collection and determine specific indexing settings for it. On using the ContainerKeys property all sources are indexed with parameters by default (default display version is used, free dimensions are absent (except for calendar one), maximum selection is applied for dimensions).

Determine container objects where it is necessary to index data sources:

Public Shared Sub Main(Params: StartParams);
Var
    //...
    MB: IMetabase;
    SearchSchema: ISolrSearchEngineSchema;
    ImportExecutor: IImportExecutor;
    SourceContext: ISourceDataImportContext;
    Containers: Array = New Integer[2];
    //...
Begin
    //...
    MB := Params.Metabase;
    //...
    //To index data sources
    ImportExecutor := SearchSchema.ImportExecutor[SearchEngineTargetType.settSourceData];
    SourceContext := ImportExecutor.CreateContext() As ISourceDataImportContext;
    //Determine indexed objects
    Containers[0] := MB.GetObjectKeyById("F_CUBES"As Integer;
    Containers[1] := MB.GetObjectKeyById("F_TSDB"As Integer;
    SourceContext.ContainerKeys := Containers;
    //...
End Sub;

Determine specific data source and indexing parameters for it:

Public Shared Sub Main(Params: StartParams);
Var
    //...
    MB: IMetabase;
    SearchSchema: ISolrSearchEngineSchema;
    ImportExecutor: IImportExecutor;
    SourceContext: ISourceDataImportContext;
    Cube: ICubeModel;
    CubeDimensions: ICubeModelDimensions;
    CubeDimension: IDimensionModel;
    SourceInfo: ISourceDataImportInfo;
    DestinationInfo: ISourceDataImportDestinationInfo;
    DimSS: IDimSelectionSet;
    DimS: IDimSelection;
    i: Integer;
    //...
Begin
    //...
    MB := Params.Metabase;
    //...
    //To index data sources
    ImportExecutor := SearchSchema.ImportExecutor[SearchEngineTargetType.settSourceData];
    SourceContext := ImportExecutor.CreateContext() As ISourceDataImportContext;
    //Specify indexed data source
    Cube := MB.ItemById["STD_CUBE"].Bind() As ICubeModel;
    CubeDimensions := Cube.Destinations.DefaultDestination.Dimensions;
    SourceInfo := SourceContext.SourceInfos.Add(Cube);
    DestinationInfo := SourceInfo.DestinationInfos.Add(Cube.Destinations.DefaultDestination);
    //Indexing parameters of display version
    DestinationInfo.GroupByDl := True;
    DestinationInfo.ImportMode := SourceImportMode.simFull;
    For i := 0 To CubeDimensions.Count - 1 Do
        CubeDimension := CubeDimensions.Item[i];
        Select Case (CubeDimension As IMetabaseObject).Id
            Case "FACTS": DestinationInfo.FreeDimensions.Add(CubeDimension);
            Case "INDICATORS""COUNTRY": DestinationInfo.KeyWordsDimensions.Add(CubeDimension);
        End Select;
    End For;
    //Set selection by dimensions
    DimSS := DestinationInfo.SelectionSet;
    For Each DimS In DimSS Do
        Select Case DimS.Dimension.Ident
            Case "FACTS""INDICATORS":
                DimS.SelectAll();
            Case "COUNTRY":
                DimS.SelectElement(0False);
                DimS.SelectElement(1False);
        End Select;
    End For;
    //...
End Sub;

After all indexed sources are determined, send the configured context to the IImportExecutor.Import method. On executing the method the required documents are generated, which will be sent for further processing and storing in the Apache Solr. On indexing the Solr instances corresponding to the specified purpose (the purpose is determined in the input parameter of the IImportExecutor.CreateContext method) and to the languages (determined in the ISolrImportContext.Locales property) are used automatically.

Public Shared Sub Main(Params: StartParams);
Var
    //...
    SearchSchema: ISolrSearchEngineSchema;
    ImportExecutor: IImportExecutor;
    SourceContext: ISourceDataImportContext;
    MbObjContext: IMbObjectsImportContext;
    //...
Begin
    //...
    //To index data sources
    ImportExecutor := SearchSchema.ImportExecutor[SearchEngineTargetType.settSourceData];
    SourceContext := ImportExecutor.CreateContext() As ISourceDataImportContext;
    //...
    //Set up context
    //...
    ImportExecutor.Import(SourceContext);
    //...
    //To index repository object metadata
    ImportExecutor := SearchSchema.ImportExecutor[SearchEngineTargetType.settMbObject];
    MbObjContext := ImportExecutor.CreateContext() As IMbObjectsImportContext;
    //...
    //Set up context
    //...
    ImportExecutor.Import(MbObjContext);
    //...
End Sub;

Indexing of Repository Objects Metadata

Several ways can be used to determine repository objects, for which it is necessary to index metadata:

After specifying required objects, send the configured context to the IImportExecutor.Import method. On executing the method the required documents are generated, which will be sent for further processing and storing in the Apache Solr. On indexing the Solr instances corresponding to the specified purpose (the purpose is determined in the input parameter of the IImportExecutor.CreateContext method) and to the languages (determined in the ISolrImportContext.Locales property) are used automatically.

Public Shared Sub Main(Params: StartParams);
Var
    //...
    MB: IMetabase;
    Schema: ISolrSearchEngineSchema;
    ImportExecutor: IImportExecutor;
    MbObjContext: IMbObjectsImportContext;
    ObjectKeys: Array Of UInteger;
    //...
Begin
    //...
    //To index repository objects metadata
    ImportExecutor := Schema.ImportExecutor[SearchEngineTargetType.settMbObject];
    MbObjContext := ImportExecutor.CreateContext() As IMbObjectsImportContext;
    //Indexed objects
    ObjectKeys := New UInteger[2];
    ObjectKeys[0] := MB.GetObjectKeyById("REGIONS_DATA");
    ObjectKeys[1] := MB.GetObjectKeyById("CITY_DATA");
    MbObjContext.Keys := ObjectKeys;
    //Indexing
    ImportExecutor.Import(MbObjContext);
    //...
End Sub;

See also:

Introduction