NeedDocumentContent: Boolean;
NeedDocumentContent: Boolean;
The NeedDocumentContent property determines whether contents of the Document objects are loaded.
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. By default the NeedDocumentContent property is set to False, file content is not loaded to the search result for the found documents.
If it is necessary to get file content, set the NeedDocumentContent property to True. The content is available in the ISearchMbObjectResult.Content or ISearchMbObjectResult.HighlightedContent properties. The content is loaded regardless the place where the value was found: in repository object metadata or in the file content.
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. Connect 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 content
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 content: " + Result.Content);
If Result.HighlightedContent <> "" Then
Debug.WriteLine("Content 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 content will be also loaded with results. Information about found documents will be displayed to the development environment console.
The requirements and result of the Fore.NET example execution match with those in the Fore example. Except assemblies determined in the Fore Example, connect also the ForeSystem 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: ISolrMbObjectsSearchContext;
Results: ISolrSearchResults;
Result: ISearchMbObjectResult;
i: Integer;
Begin
MB := Params.Metabase;
//Parameters of search and indexing set for repository
SharedParams := MB.SpecialObject[MetabaseSpecialObject.msoSharedParams].Bind() As ISharedParams;
SearchEngine := SharedParams.SearchEngine As ISolrSearchEngineService;
Schema := SearchEngine.SearchEngineSchema As ISolrSearchEngineSchema;
//Search parameters
Schema.SearchOptions.UseSmartSearch := False;
SearchExecutor := Schema.SearchExecutor[SearchEngineTargetType.settMbObject];
SearchContext := SearchExecutor.CreateContext() As ISolrMbObjectsSearchContext;
SearchContext.Locale := LocaleCodeID.lcidRussian;
//Get document content
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 As Integer) Then
System.Diagnostics.Debug.WriteLine("Object: " + Result.Name + '(' + Result.Id + ')');
System.Diagnostics.Debug.WriteLine("Date and time of the last change: " + Result.Timestamp);
If Result.Content <> "" Then
System.Diagnostics.Debug.WriteLine("Document content: " + Result.Content);
If Result.HighlightedContent <> "" Then
System.Diagnostics.Debug.WriteLine("Content with highlighted search value: " + Result.HighlightedContent);
End If;
End If;
End If;
End For;
End Sub;
See also: