ISolrSearchResult.CustomFieldSearchResults

Fore Syntax

CustomFieldSearchResults: ISolrCustomFieldSearchResults;

Fore.NET Syntax

CustomFieldSearchResults: Prognoz.Platform.Interop.BISearch.ISolrCustomFieldSearchResults;

Description

The CustomFieldSearchResults property returns search results by custom fields.

Fore Example

It is supposed that the repository is set to work with search service based on Apache Solr. Search service base contains indexed metadata of various repository objects. Add links to the BISearch, Fore, Metabase system assemblies.

Sub UserProc;
Var
    MB: IMetabase;
    SharedParams: ISharedParams;
    SearchEngine: ISolrSearchEngineService;
    Schema: ISolrSearchEngineSchema;
    SearchExecutor: ISearchExecutor;
    SearchContext: ISolrSourceDataSearchContext;
    Results: ISolrSearchResults;
    Result: ISolrSearchResult;
    CustomResults: ISolrCustomFieldSearchResults;
    CustomResult: ISolrCustomFieldSearchResult;
    i, j: Integer;
    s: Variant;
Begin
    MB := MetabaseClass.Active;
    //Search and indexing parameters specified for repository
    SharedParams := MB.SpecialObject(MetabaseSpecialObject.SharedParams).Bind As ISharedParams;
    SearchEngine := SharedParams.SearchEngine As ISolrSearchEngineService;
    Schema := SearchEngine.SearchEngineSchema As ISolrSearchEngineSchema;
    //Search parameters
    SearchExecutor := Schema.SearchExecutor(SearchEngineTargetType.SourceData);
    SearchContext := SearchExecutor.CreateContext As ISolrSourceDataSearchContext;
    SearchContext.Locale := LocaleCodeID.Russian;
    SearchContext.Text := "Russia";
    //Search
    Results := SearchExecutor.Search(SearchContext) As ISolrSearchResults;
    For i := 0 To Results.Count - 1 Do
        Result := Results.Item(i) As ISolrSearchResult;
        CustomResults := Result.CustomFieldSearchResults;
        If CustomResults.Count > 0 Then
            Debug.WriteLine("Index of the records with search results: " + i.ToString);
            Debug.WriteLine("Identifier of the document with indexed data: " + Result.DocId);
            For j := 0 To CustomResults.Count - 1 Do
                CustomResult := CustomResults.Item(j);
                Debug.WriteLine("Custom field: " + CustomResult.SolrField.Id);
                Debug.Indent;
                Debug.WriteLine("Values:");
                For Each s In CustomResult.Values Do
                    Debug.Write(s + " ");
                End For;
                Debug.WriteLine("");
                If CustomResult.HighlightedValues.Length > 0 Then
                    Debug.WriteLine("Values with highlighting of searched value:");
                    For Each s In CustomResult.HighlightedValues Do
                        Debug.Write(s + " ");
                    End For;
                    Debug.WriteLine("");
                End If;
                Debug.Unindent;
            End For;
            Debug.WriteLine("------");
        End If;
    End For;
End Sub UserProc;

After executing the example the specified value by indexed information about dimension elements will be searched. Indexed values of custom fields will be excluded from the search result. Values will be displayed in the development environment console.

Fore.NET Example

The requirements and result of the Fore.NET example execution match with those in the Fore example. Along with the assemblies determined in the Fore example, also add a link to the System assembly.

Imports Prognoz.Platform.Interop.BISearch;
Imports Prognoz.Platform.Interop.ForeSystem;
Imports Prognoz.Platform.Interop.KeFore;
Imports Prognoz.Platform.Interop.Metabase;

Public Shared Sub Main(Params: StartParams);
Var
    MB: IMetabase;
    SharedParams: ISharedParams;
    SearchEngine: ISolrSearchEngineService;
    Schema: ISolrSearchEngineSchema;
    SearchExecutor: ISearchExecutor;
    SearchContext: ISolrSourceDataSearchContext;
    Results: ISolrSearchResults;
    Result: ISolrSearchResult;
    CustomResults: ISolrCustomFieldSearchResults;
    CustomResult: ISolrCustomFieldSearchResult;
    i, j: Integer;
    s: Object;
Begin
    MB := Params.Metabase;
    //Search and indexing parameters specified for repository
    SharedParams := MB.SpecialObject[MetabaseSpecialObject.msoSharedParams].Bind() As ISharedParams;
    SearchEngine := SharedParams.SearchEngine As ISolrSearchEngineService;
    Schema := SearchEngine.SearchEngineSchema As ISolrSearchEngineSchema;
    //Search parameters
    SearchExecutor := Schema.SearchExecutor[SearchEngineTargetType.settSourceData];
    SearchContext := SearchExecutor.CreateContext() As ISolrSourceDataSearchContext;
    SearchContext.Locale := LocaleCodeID.lcidRussian;
    SearchContext.Text := "Russia";
    //Search
    Results := SearchExecutor.Search(SearchContext) As ISolrSearchResults;
    For i := 0 To Results.Count - 1 Do
        Result := Results.Item[i] As ISolrSearchResult;
        CustomResults := Result.CustomFieldSearchResults;
        If CustomResults.Count > 0 Then
            System.Diagnostics.Debug.WriteLine("Index of record with search results: " + i.ToString());
            System.Diagnostics.Debug.WriteLine("Identifier of document with indexed data: " + Result.DocId);
            For j := 0 To CustomResults.Count - 1 Do
                CustomResult := CustomResults.Item[j];
                System.Diagnostics.Debug.WriteLine("Custom field: " + CustomResult.SolrField.Id);
                System.Diagnostics.Debug.Indent();
                System.Diagnostics.Debug.WriteLine("Values:");
                For Each s In CustomResult.Values Do
                    System.Diagnostics.Debug.Write(s + " ");
                End For;
                System.Diagnostics.Debug.WriteLine("");
                If CustomResult.HighlightedValues.Length > 0 Then
                    System.Diagnostics.Debug.WriteLine("Values with highlighting of searched value:");
                    For Each s In CustomResult.HighlightedValues Do
                        System.Diagnostics.Debug.Write(s + " ");
                    End For;
                    System.Diagnostics.Debug.WriteLine("");
                End If;
                System.Diagnostics.Debug.Unindent();
            End For;
            System.Diagnostics.Debug.WriteLine("------");
        End If;
    End For;
End Sub;

See also:

ISolrSearchResult