Making dtSearch highlight one hit per phrase, rather than one hit per word-in-a-phrase
Posted
by Chris
on Stack Overflow
See other posts from Stack Overflow
or by Chris
Published on 2010-04-26T20:01:34Z
Indexed on
2010/04/26
20:03 UTC
Read the original article
Hit count: 454
dtsearch
|hit-highlighting
I'm using dtSearch to highlight text search matches within a document. The code to do this, minus some details and cleanup, is roughly along these lines:
SearchJob sj = new SearchJob();
sj.Request = "\"audit trail\""; // the user query
sj.FoldersToSearch.Add(path_to_src_document);
sj.Execute();
FileConverter fileConverter = new FileConverter();
fileConverter.SetInputItem(sj.Results, 0);
fileConvert.BeforeHit = "<a name=\"HH_%%ThisHit%%\"/><b>";
fileConverter.AfterHit = "</b>";
fileConverter.Execute();
string myHighlightedDoc = fileConverter.OutputString;
If I give dtSearch a quoted phrase query like
"audit trail"
then dtSearch will do hit highlighting like this:
An <a name="HH_0"/><b>audit</b> <a name="HH_1"/><b>trail</b> is a fun thing to have an <a name="HH_2"/><b>audit</b> <a name="HH_last"/><b>trail</b> about!
Note that each word of the phrase is highlighted separately. Instead, I would like phrases to get highlighted as whole units, like this:
An <a name="HH_0"/><b>audit trail</b> is a fun thing to have an <a name="HH_last"/><b>audit trail</b> about!
This would A) make highlighting look better, B) improve behavior of my javascript that helps users navigate from hit to hit, and C) give more accurate counts of total # hits.
Is there good ways to make dtSearch highlight phrases this way?
© Stack Overflow or respective owner