Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching for text within a specified paragraph

Status
Not open for further replies.

gk17

Technical User
Sep 6, 2013
86
US
Hi,

I have a field that contains patient reports in them. I want to search for the word "Summary" in the report (which is usually in the end of these reports) and then do a search within that paragraph or two for specific keywords (which will be entered by the user). Here's what I need for this report:

- Search only within the text AFTER the word "Summary"
- Within the Summary, user will specify (via report parameters) keyword(s) to search for there. Will need to allow multiple keywords, maybe separated by commas for each keyword(s)

The above will be in the record selection and will return the report ID. I don't need the report or text itself. My main problem now is figuring out how to do the above two items.

Using Crystal Reports XI.

Thanks.

Kevin.
 
You can get the text after "Summary" (if there is a summary always and only one summary in that field) by using the Split function.
split({YourDataField},"Summary")[2]

 
Thanks for the reply BettyJ.

I don't want the actual text returned. I will be using other fields in the report which will have the data we need. Can we add that in the record selection? We also need a way to search for keywords (comma separated if more than one word) in the summary using a {?Keywords} parameter.
 
Create a formula
@TextAfterSummary
[tt]split({YourDataField},"Summary")[2][/tt]

Record Selection Formula
[tt]@TextAfterSummary LIKE split({?Keywords},",")[/tt]
 
I would tackle it this way.
[ol 1]
[li]Set the parameter to allow multiple values rather than using a single parameter with search terms separated by commas;[/li]
[li]Use the following Record Selection Formula:[/li]
[/ol]

Code:
Instr({Table.YourField}, 'Summary') > 0 and
(
    (
        Instr(Instr({Table.YourField}, 'Summary'),{Table.YourField}, {?Parameter}[1]) > 0 
    )
    or
    (
        UBound ({?Parameter}) > 1 and
        Instr(Instr({Table.YourField}, 'Summary'), {Table.YourField}, {?Parameter}[2]) > 0 
    )
    or
    (
        UBound ({?Parameter}) > 2 and
        Instr(Instr({Table.YourField}, 'Summary'), {Table.YourField}, {?Parameter}[3]) > 0 
    )
)

This code allows for up to 3 search terms in the parameter. If you will be using more than 3 search terms, just add extra components to the code following the same logic, up to the maximum expected search terms.

My logic allows for the word 'Summary' and any of the search terms. If you require only records with all of the search terms you will need to replace the "or"s in the code with "and"s.

Hope this helps.

Cheers
Pete
 
Thank you both for the replies. We're not sure if they have a set number of keywords which is why I wanted to go with the comma delimited method. I will give both of these a try to see which one works best for us.
 
Instead of using a parameter where multiple keywords are separated by a comma, if you use a string parameter and setting the option Allow Multiple Values to True, you can use the following to allow any number of keywords.

I got this from another site, but modified it a little bit.

Create a custom function
SepKeyWords
Function (stringvar array params)
Split( Join(params, ",") , ",")

Record Selection
@TextAfterSummary LIKE SepKeyWords({?Keywords})

To display the parameters separated by commas:
@DisplayParameters
Join( {?Keywords}, ", ")
 
Would that require me to "package" the report so it can be run as a stand-alone app? I don't know how to do that and the users we have will be using another application which uses Crystal Reports in the background to generate these reports. Would like that to learn how to create reports as a stand-alone one day.

BettyJ, I tried using your formula and record selection but had an error for the formula -> "A subscript must be between 1 and the size of the array"

Pete, I also tried to see if I can get the record selection you posted to work for the time being and it's returning an error saying "An array is required here" for those lines that have the "UBound ({?Parameter}) > 1" Since the users won't be using Crystal Reports directly to run these reports (will be done via a third party system), how can I hard code keywords into it? I tried the following but that seems to search the entire text field and not just text after the "Summary" section:

Code:
Instr({Table.YourField}, 'Summary') > 0 and
(
Instr(Instr({Table.YourField}, 'Summary'), {Table.YourField}, 'abc') > 0 or
Instr(Instr({Table.YourField}, 'Summary'), {Table.YourField}, 'def') > 0 or
Instr(Instr({Table.YourField}, 'Summary'), {Table.YourField}, 'ghi') > 0 or
Instr(Instr({Table.YourField}, 'Summary'), {Table.YourField}, 'jkl') > 0
)

What happens if there is more than one "Summary" showing in the report? I forgot that this could happen where they might go in and make changes with an updated summary.

Thanks.
 
You will get the error "A subscript must be between 1 and the size of the array" if there is no Summary in that field. So modify the formula as follows:

@TextAfterSummary
if "Summary" in {YourDataField} then
split({YourDataField},"Summary")[2]

 
This formula can be used to check if there are more than one Summary in the report.

0 - no "Summary"

2 - 1 "Summary"
3 - 2 "Summary"
4 - 3 "Summary" ...


stringvar array split_report;
numbervar length_array;
if "Summary " in {YourDataField} then
(split_report:=split({YourDataField},"Summary");
length_array:=ubound(split_report));

 
Please change the custom function to:

SepKeyWords
[tt]Function (stringvar array params)
Split("*" + Join(params, "*,*") + "*", ",")[/tt]

By the way, are you able to create the custom report function?

I tested this and it worked for me. You should be able to get what you are looking for. I am not exactly sure what you want the report to do when there is more than one "Summary".

Also, my report worked fine when run inside another application.
 
What do you mean by custom report? I can have direct access to Crystal Reports and can create main or sub reports. Not sure if that answers your question.

Is that a new function completely separate from the ones you posted earlier? I'm not sure if I know how to use that within my report.

I think the code posted earlier will work for the most part:

Code:
Instr({Table.YourField}, 'Summary') > 0 and
(
Instr(Instr({Table.YourField}, 'Summary'), {Table.YourField}, 'abc') > 0 or
Instr(Instr({Table.YourField}, 'Summary'), {Table.YourField}, 'def') > 0 or
Instr(Instr({Table.YourField}, 'Summary'), {Table.YourField}, 'ghi') > 0 or
Instr(Instr({Table.YourField}, 'Summary'), {Table.YourField}, 'jkl') > 0
)

We will let it be if there are more than one Summary section. Just one more item. If I want to exclude a certain word from the Summary section, how would I go about doing this? Does spacing matter? For example, if I want all the above keywords in the code box but want to exclude 'some keywords here'

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top