Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Oracle Text question
Jeremy wrote:
> In article <1163503498.412454.110510_at_f16g2000cwb.googlegroups.com>,
> Vladimir M. Zakharychev says...
>
>
>
> >
> > Yes, it's possible to highlight search terms in the document. See the
> > docs on CTX_DOC package in Text Reference, MARKUP and HIGHLIGHT
> > procedures.
> >
> Thanks Vladimir, I don't see something there that describes how to pull
> out a section of the document containing the keywords as a kind of 2 or
> 3 line summary. I have used the highlights OK so that when the user is
> looking at the complete document, the keywords are highlighted.
>
> Thanks anyway.
>
> --
> jeremy
Well, you can't do that with OOTB functionality. However, since HIGHLIGHT procedure gives you offsets into the filtered document and lengths of segments to be highlighted, it's not much of a problem to use dbms_lob.substr() to extract part of the document a few chars before the first highlight area and a few chars after it, surround it with ellipsis and present that to the user. Something like this, for example:
create or replace
function get_highlighted_docpart( p_ctxidx in varchar2, p_docid in
varchar2, p_query in varchar2, p_amt in pls_integer := 100)
return varchar2
is
l_hitab ctx_doc.highlight_tab; l_doc clob; l_start pls_integer;
||'<b><span style="color:red">' ||dbms_lob.substr(l_doc,l_hitab(1).length,l_hitab(1).offset) ||'</span></b>' ||dbms_lob.substr(l_doc, p_amt,
Of course, this implementation is very basic and can be improved in
many ways, it's just something I came up with as quickly as I could
type. :) For example, it doesn't handle the case where two or more
occurences of the query term fall into the extracted document part, in
which case all of them should be highlighted, not just the first one;
it doesn't allow to change highlighting style, it's always red bold
face. But it does the basic job of extracting relatively short area
surrounding the search term. Google does it a bit differently: they
extract one or two complete sentences including the search term, not
just immediate neighbourhood of the term, but that's not too hard to
implement either.
Hth,
Vladimir M. Zakharychev
N-Networks, makers of Dynamic PSP(tm)
http://www.dynamicpsp.com
Received on Tue Nov 14 2006 - 12:19:20 CST