You are here: Symbol Reference > dtSearch.Engine Namespace > Classes > SearchReportJob Class
Close
dtSearch .NET Standard API 2024.02
SearchReportJob Class

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

dtSearch.Engine.JobBase | dtSearch.Engine.OutputBase | dtSearch.Engine.SearchReportJob
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 

Format 

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:

Symbol
Meaning
Filename
The name of the file (without path information). For PDF and HTML files, this will be the Title.
Location
The location of the file
Fullname
The path and filename of the file.
Size
File size in bytes
SizeK
File size in kilobytes
Date
Modification date of the file when indexed
Hits
Number of hits in the file
Title
The first 80 characters of the file
The docId of the file
Type
The file type (Microsoft Word, PDF, HTML, etc.)
Ordinal
The 1-based ordinal of this item in the SearchResults from which it was generated
IndexRetrievedFrom
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:

Symbol
Meaning
Page
Page number where the hit occurs
Paragraph
Paragraph number where the hit occurs (relative to the start of the page)
Word
Word offset of the block of context from the beginning of the file.
FirstHit
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.

Example
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();
IDisposable

SearchReportJob requires the IDisposable Pattern.

Show:
No members matching the current filter
Show:
No members matching the current filter
Copyright (c) 1998-2023 dtSearch Corp. All rights reserved.