dtSearch .NET Standard API 2023.02
SearchReportJob Class

Generates a report showing each hit in one or more documents, with a specified amount of context

public class SearchReportJob : OutputBase;

To generate a search report, 

(1) Start with a SearchResults object representing the results of a search. 

(2) Call SearchJob.NewSearchReportJob to make a SearchReportJob 

(3) Select the items to include in the search report using the Select*() methods in SearchReportJob 

(4) Specify the amount of context to include using WordsOfContextExact, ParagraphsOfContext, or WordsOfContext 

(5) Set the output format for the report using ContextFooter, ContextHeader, etc. 

(6) Call Execute() to generate the report 


A search report lists the hits found in one or more documents, with each hit surrounded by a specified amount of context. Each block of context starts with a ContextHeader and ends with the ContextFooter. Contiguous or overlapping blocks of context will be combined. The amount of context included in the report can be specified by words or by paragraphs. 

Each block of context is constructed as follows:

[ContextHeader] ...text... [BeforeHit] hit [AfterHit] ...text... [ContextFooter]

The report as a whole is constructed as follows:

[Header] [FileHeader] [ContextHeader] ...text... [BeforeHit] hit [AfterHit] ...text... [ContextFooter] [ContextSeparator] [ContextHeader] ...text... [BeforeHit] hit [AfterHit] ...text... [ContextFooter] ... more blocks of context, if present [FileFooter] ... more files ... [Footer]


Use the following symbols to insert file information into the FileHeader and FileFooter:

The name of the file (without path information). For PDF and HTML files, this will be the Title.
The location of the file
The path and filename of the file.
File size in bytes
File size in kilobytes
Modification date of the file when indexed
Number of hits in the file
The first 80 characters of the file
The docId of the file
The file type (Microsoft Word, PDF, HTML, etc.)
The 1-based ordinal of this item in the SearchResults from which it was generated
The index where the file was found

Use %% around each symbol, like this: %%FullName%% 

Use the following symbols to insert context information in the ContextHeader, which appears in front of each block of context:

Page number where the hit occurs
Paragraph number where the hit occurs (relative to the start of the page)
Word offset of the block of context from the beginning of the file.
Word offset of the first hit in the block of context.
Adding Hits in Context to Search Results

You can use SearchReportJob to add a brief snippet of text to each SearchResults item showing a few hits with a limited amount of context around each hit. This "synopsis" can then be included in the displayed search results to make it easier for end-users to see why each document was found. 

To add a synopsis to SearchResults

1. Use MaxContextBlocks to limit the number of blocks of context included in the report. For example, if MaxContextBlocks = 1, then only the first hit will be included. 

2. Use WordsOfContextExact to specify the number of words of context to included. 

3. Set the OutputFormat to itUnformattedHTML, so output characters will be correctly HTML-encoded and formatting from the original document will not appear in the search results list. (If you use itHTML as the output format, the output could contain paragraph breaks, color changes, etc., that would not look right in a search results table.) 

4. Set the dtsReportStoreInResults flag in SearchReportJob, which causes the synopsis to be stored in each search results item, making it easier to access the individual synopsis items. 

5. Set the BeforeHit and AfterHit marks to HTML tags like <b> and </b> to mark the hits. 

6. Select a range of items to include in the search report that corresponds to the range items to be displayed. For example, if you are displaying the first ten items, select items 0 through 9. Generating a synopsis can be time-consuming, so it is important to generate it only when needed for display.

Caching Text to Optimize SearchReportJob

Generation of a synopsis is much faster if you index the documents with caching of text enabled, because the context can be extracted from the index without the need to access the original files, and because the cached text includes tables designed to make context extraction more efficient.

reportJob.SelectRange(startAt, endAt); reportJob.WordsOfContextExact = 10; reportJob.BeforeHit = "<b>"; reportJob.AfterHit = "</b>"; reportJob.MaxContextBlocks = 3; reportJob.ContextSeparator = "<br>"; reportJob.ContextHeader = "..."; reportJob.ContextFooter = "..."; reportJob.SetOutputToString(512000); reportJob.Flags = ReportFlags.dtsReportStoreInResults | ReportFlags.dtsReportLimitContiguousContext | ReportFlags.dtsReportGetFromCache; reportJob.OutputFormat = it_UnformattedHTML); reportJob.Execute();

SearchReportJob requires the IDisposable Pattern.