How to generate a synopsis to display in search results

Article: DTS0194

Applies to: dtSearch Engine 6.5 and later


The SearchReportJob object in the dtSearch Engine API provides a way to extract a few words of context around each hit. For example, see:

For more information on the SearchReportJob object, see:
SearchReportJob (.NET)
SearchReportJob (VB/COM/ASP)
SearchReportJob (Java)
DSearchReportJob (C++)

Index with caching of text enabled

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.   Caching text is also helpful when the page may not be accessible to the dtSearch Engine when the search report is generated.  This article explains how to enable caching using dtSearch Desktop:

This article explains how to use caching in the dtSearch Engine's developer API:

Generating a synopsis

Use the following settings in SearchReportJob to generate a brief hits-in-context string to show in search results:

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 instead of WordsOfContext -- otherwise SearchReportJob will return whole paragraph-sized blocks.

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.

Displaying the synopsis

After the search report has been generated, for each item in search results, there will be an HTML string containing the extracted synopsis.  

To access the synopsis in each item in search results:
C/C++:  Use dtsSearchResultsItem.synopsis
.NET:  Use SearchResultsItem.Synopsis
VB/ASP: Use SearchResults.DocDetailItem("_synopsis")
Java:  Use SearchResults.getDocDetailItem("_synopsis")

Sample code

For sample code demonstrating how to generate and display a synopsis in search results, see the sample application in C:\Program Files\dtSearch Developer\examples\asp.net2 (.NET 2.0 and later).


Copyright © 1991-2022 dtSearch Corp. All Rights Reserved.  /  Terms of use  /  Privacy