[ic] return section of text that contain search term
Aaron Hazelton
interchange-users@icdevgroup.org
Thu Jan 2 18:14:01 2003
Jerry wrote:
> > I would like to return a section of text in context around a
> > search term. I am wondering if anyone has done this. I
> > could have sworn I had seen something like this before on
> > an earlier version of the ICDEV site, but maybe not. What
> > I am going for is something similar to what Google does
> > on their results, only not as jazzy -- I just do not want to
> > return the whole db value as it may be quite long ....
> >
> > Has anyone done this? Any ideas on it? input? direction?
>
> Assuming you are returning something like [item-description] from
> your search. Something like this would work if I understand your
> question correctly.
>
> [calc]
> # Set the maximum length of the string you want to display
> $max_length = 25;
> $out = q{[item-description]};
> if (length($out) > $max_length) {
> $out = substr($out,0,$max_length);
> # In case we chopped up a word, backup to the last space
> $out =~ s/ [^ ]*$//;
> # add some ... to the end of the string
> return $out . " ...";
> }
> return $out;
> [/calc]
Thanks Jerry and Mike. If I did thie correctly, this limits
the total length of the string returned. This can be done
with a [filter ... as well. What I wanted was to return a
limited portion of the text *around* the search term in a
context form. If that's what you are talking about as well
then I am missing something I guess.
With the code you posted, I guess you would have to
find the search term in the text, then go either direction, but
I do not know perl. Any ideas on how to do that?
Thanks again!
>
> Think this is what you want...
>
> Jerry
--
Aaron