ISolrSearchResult.CustomFieldSearchResults

Syntax

CustomFieldSearchResults: ISolrCustomFieldSearchResults;

Description

The CustomFieldSearchResults property returns search results by custom fields.

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.

See also:

ISolrSearchResult