The text is read from the index if the index stores the texts of the documents; otherwise the document is extracted again from the file at its path. A document that the index does not contain is not highlighted, and the ErrorOccurred event reports it. The found document must come from a search of this index or from a trusted source: an indexed document is highlighted by its path, so an application that gets found documents from its users must check that a user may read the document.
The text is divided into words by the built-in division: a document that was indexed with a custom word splitter is highlighted with the options that have the same splitter, see Highlight and WordSplitter.
Examples
The example demonstrates how to highlight occurrences in HTML formatted text.
stringindexFolder=@"c:\MyIndex\";stringdocumentFolder=@"c:\MyDocuments\";// Creating an indexIndexindex=newIndex(indexFolder);// Indexing documents from the specified folderindex.Add(documentFolder);// Search for the word 'eternity'SearchResultresult=index.Search("eternity");// Highlighting occurrences in textif(result.DocumentCount>0){FoundDocumentdocument=result.GetFoundDocument(0);// Getting the first found documentOutputAdapteroutputAdapter=newFileOutputAdapter(OutputFormat.Html,@"c:\Highlighted.html");// Creating an output adapter to the fileHighlighterhighlighter=newDocumentHighlighter(outputAdapter);// Creating the highlighter objectindex.Highlight(document,highlighter);// Generating HTML formatted text with highlighted occurrences}
The text is read from the index if the index stores the texts of the documents; otherwise the document is extracted again from the file at its path. A document that the index does not contain is not highlighted, and the ErrorOccurred event reports it. The found document must come from a search of this index or from a trusted source: an indexed document is highlighted by its path, so an application that gets found documents from its users must check that a user may read the document.
A document that was indexed with a custom word splitter (see WordSplitter) is divided into words by the splitter of the options (see WordSplitter): the options must have the same splitter, otherwise the words that the built-in division does not give are not highlighted.
Examples
The example demonstrates how to highlight occurrences in HTML formatted text.
stringindexFolder=@"c:\MyIndex\";stringdocumentFolder=@"c:\MyDocuments\";// Creating an indexIndexindex=newIndex(indexFolder);// Indexing documents from the specified folderindex.Add(documentFolder);// Search for the word 'eternity'SearchResultresult=index.Search("eternity");// Highlighting occurrences in textif(result.DocumentCount>0){FoundDocumentdocument=result.GetFoundDocument(0);// Getting the first found documentOutputAdapteroutputAdapter=newFileOutputAdapter(OutputFormat.Html,@"c:\Highlighted.html");// Creating an output adapter to the fileHighlighterhighlighter=newDocumentHighlighter(outputAdapter);// Creating the highlighter objectHighlightOptionsoptions=newHighlightOptions();// Creating the highlight options objectoptions.HighlightColor=newColor(0,255,0);// Setting the highlight colorindex.Highlight(document,highlighter,options);// Generating HTML formatted text with highlighted occurrences}