NeedDocumentContent: Boolean;
NeedDocumentContent: Boolean;
The NeedDocumentContent property determines whether contents of the Document objects are loaded.
If there are indexed documents, the search is executed by their metadata (name, identifier and other metadata) and by contents 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.
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.
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: 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 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 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: