ISolrMbObjectsSearchContext.NeedDocumentContent

Syntax

NeedDocumentContent: Boolean;

Description

The NeedDocumentContent property determines whether contents of the Document objects are loaded.

Comments

If there are indexed documents, the search is performed by their metadata (name, identifier and other metadata) and by content of the file which was loaded to the document. The NeedDocumentContent property is set to False by default, file contents is not loaded to the search result for the found documents.

If it is necessary to get file contents, set the NeedDocumentContent property to True. The contents is available in the ISearchMbObjectResult.Content or ISearchMbObjectResult.HighlightedContent properties. The contents is loaded regardless of where the value was found: in repository object metadata or in the file contents.

Example

It is supposed that the repository is set up 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: ISolrMbObjectsSearchContext;
    Results: ISolrSearchResults;
    Result: ISearchMbObjectResult;
    i: Integer;
Begin
    MB := MetabaseClass.Active;
    //Parameters of search and indexing set for repository
    SharedParams := MB.SpecialObject(MetabaseSpecialObject.SharedParams).Bind As ISharedParams;
    SearchEngine := SharedParams.SearchEngine As ISolrSearchEngineService;
    Schema := SearchEngine.SearchEngineSchema As ISolrSearchEngineSchema;
    //Search parameters
    Schema.SearchOptions.UseSmartSearch := False;
    SearchExecutor := Schema.SearchExecutor(SearchEngineTargetType.MbObject);
    SearchContext := SearchExecutor.CreateContext As ISolrMbObjectsSearchContext;
    SearchContext.Locale := LocaleCodeID.Russian;
    //Get document contents
    SearchContext.NeedDocumentContent := True;
    SearchContext.Text := "Annual report 2016";
    //Search
    Results := SearchExecutor.Search(SearchContext) As ISolrSearchResults;
    //View search results
    For i := 0 To Results.Count - 1 Do
        Result := Results.Item(i) As ISearchMbObjectResult;
        //Display information only by found documents
        If Result.ClassId = MetabaseObjectClass.KE_CLASS_DOCUMENT Then
            Debug.WriteLine("Object: " + Result.Name + '(' + Result.Id + ')');
            Debug.WriteLine("Date and time of the last change: " + Result.Timestamp);
            If Result.Content <> "" Then
                Debug.WriteLine("Document contents: " + Result.Content);
                If Result.HighlightedContent <> "" Then
                    Debug.WriteLine("Contents with highlighted search value: " + Result.HighlightedContent);
                End If;
            End If;
        End If;
    End For;
End Sub UserProc;

On executing the example the specified value by indexed metadata of repository objects will be searched. If search value is found in documents, their contents will also be loaded with results. Information about found documents will be displayed in the development environment console.

See also:

ISolrMbObjectsSearchContext