dtSearch Text Retrieval Engine Programmer's Reference

Search flag to get a list of the words or phrases matched in a document.

The dtsSearchWantHitsByWord search flag tells the dtSearch Engine to generate a list of the words that were matched in each document found in a search. This is what the data returned looks like, after a search for apple pie and bana*:

apple pie, 7; bana*, 4

The list shows each term from the search request that was found, and the number of hits. If the dtsSearchWantHitsArray flag is also set, the list includes the word offsets of the hits:

apple pie, 7 (482 499 552 578 589 683 706 ); bana*, 4 (490 505 689 713 )

Fields. If the search includes a field criterion, the matching field is listed after the hit count and hits. For example, if the search was for subject contains apple pie, the hitsByWord report would look like this:

apple pie, 7 (482 499 552 578 589 683 706 ), subject

The field is listed only if it was part of the search request, so a search for apple pie would not include subject in the hitsByWord report, even if apple pie happened to be found in that field. 

Phrases. The hitsByWord report treats each instance of a phrase as a single hit. This differs from the way hits are counted in search results, where a "hit" is always a single word. For example, so if "apple pie" occurs 7 times in a document, the document would have 14 hits reported in the search results list. When the dtsSearchWantHitsByWord flag is set, the search results list will include a phraseCount value for each document indicating the number of hits found, with each phrase counted as a single hit. 

Ordinals. Set the flag dtsSearchWantHitsByWordOrdinals to add zero-based ordinals in front of each term, like this:  

[0]apple pie, 7 (482 499 552 578 589 683 706 ); [1]bana*, 4 (490 505 689 713 )

The ordinals will be consistent for all documents retrieved, regardless of which terms are retrieved in each document. For example, if a document only includes "bana*", it would still have ordinal [1] instead.

Accessing HitsByWord after a search

C++: dtsSearchResultsItem.hitsByWord 

.NET: SearchResultsItem.HitsByWord 

Java: SearchResults.getDocDetailItem("_hitsByWord") 

COM: SearchResults.DocDetails or SearchResults.DocDetailItem("_hitsByWord")