You are here: Overviews > Highlighting Hits > Hit navigation
Close
dtSearch Text Retrieval Engine Programmer's Reference
Hit navigation

How to implement "next hit" and "previous hit" navigation features.

In addition to highlighting hits, it is often helpful to enable users to quickly jump from hit to hit using "Next Hit" and "Prev Hit" buttons in your user interface. The dtSearch Engine's hit highlighting API supports this feature by providing a way to number the "BeforeHit" and "AfterHit" markings. 

When the BeforeHit and AfterHit marks are inserted, the strings "%%ThisHit%%", "%%NextHit%%", and "%%PrevHit%%" will be replaced with ordinals representing the current hit, the next hit, and the previous hit in the document. For example, the following code makes the beforeHit and nextHit marks act as HTML "Previous Hit" and "Next Hit" buttons.

job.beforeHit = "<A NAME=\"hit%%ThisHit%%\"></A>" "<A HREF=\"#hit%%PrevHit%%\">" "<IMG SRC=\"hit1.gif\" ALIGN=\"middle\" ALT=\"[Prev Hit]\" BORDER=0></A>"; job.afterHit = "<A HREF=\"#hit%%NextHit%%\">" "<IMG SRC=\"hit2.gif\" ALIGN=\"middle\" ALT=\"[Next Hit]\" BORDER=0></A>";

Sequential integers are used to identify each hit except for the last, which is named _last. For example, if BeforeHit = "xxx%%ThisHit%%", then "xxx1" would appear before the first hit, "xxx2" before the second hit, and so forth, with "xxx_last" in front of the last hit. 

For sample JavaScript code implementing hit navigation using these tags, see the file hitnav.js in the ASP sample included with the dtSearch Engine.

Copyright (c) 1995-2021 dtSearch Corp. All rights reserved.