• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Need Help with Replace Boolean Syntax

Participant ,
Feb 13, 2024 Feb 13, 2024

Copy link to clipboard

Copied

OK.  One last item to cure with respect to applicant searches.

In CF 4.51 the collection for applicants was based on a huge folder containing .txt files.

In CF 2023 the colleciton is based on a huge folder containg: .doc, .docx, .pdf & .txt files.

 

The code that worked against the .txt file collection was.

****************************

values (#getCurrentSearchID.theSearchID#, #Replace( replace( URL, "/", "" ), ".txt", "" )#)

****************************

Basically, it stripped off the .txt part of the file name & the "/" that solr inserts into the value of URL> so that we are left with the file # to use in further processing.

I have tried the following against the folder with the 4 extensions mentioned above.

***************************

values (#getCurrentSearchID.theSearchID#, #Replace( replace( URL, "/", "" ), (".doc" or ".docx" or ".txt") ", "" )#)

***************************

CF is not happy with my (".doc" or ".docx" or ".txt") construct.  Would very much appreciate any suggestions.   Would like to avoid CFIF/CFELSE searching each URL returned to see which extension is involved before continuing to process the data, if that is even possible.

 

Alex Craig, General Manager
"Avid Saltwater Fly Fisherman"
TOPICS
Builder , Getting started

Views

116

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Feb 13, 2024 Feb 13, 2024

Simple as pie:

ReplaceNoCase(ReplaceNoCase(ReplaceNoCase(ReplaceNoCase( replace( URL, "/", "" ), ".doc", "" ), ".docx", "" ), ".txt", "" ), ".pdf", "" )

Votes

Translate

Translate
Engaged ,
Feb 13, 2024 Feb 13, 2024

Copy link to clipboard

Copied

Is this what you're looking for?  Replacing all those extensions in one line?

Replace(Replace(Replace( replace( URL, "/", "" ), ".doc", "" ), ".docx", "" ), ".txt", "" )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 13, 2024 Feb 13, 2024

Copy link to clipboard

Copied

Hmm ...

So what this will do is search for all of them and only delete the one that actually exists AND NOT produce an error for those extensions that are not in the URL.  I"ll need to add one more for the .pdf files as well.  Does this look right to you?

Replace(Replace(Replace(Replace( replace( URL, "/", "" ), ".doc", "" ), ".docx", "" ), ".txt", "" ), ".pdf", "" )

Alex Craig, General Manager
"Avid Saltwater Fly Fisherman"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 13, 2024 Feb 13, 2024

Copy link to clipboard

Copied

That's correct.  If there is no 'docx' to replace, it just moves on to .txt, then .pdf.  No errors.

 

Might not be the most elegant line of code ever, but gets the job done.

 

Alternatively, I guess you could use listEach():

<cfset theString = replace( URL, "/", "" )>

<cfset alist = ".doc,.docx,.txt,.pdf">

<cfset listEach(alist,function(idx){
    theString = replace(theString,idx,'');
})>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 13, 2024 Feb 13, 2024

Copy link to clipboard

Copied

Your suggestion works!  However, there is one wrinkle.  It is case sensitive.  Resumes are entered into the system by individual candidates some of whom used upper case (e.g. ".DOC").  I can add four more extensions.  But there is always the possibility of outliers like .Doc.

I don't suppose there is anyway to drive the string case-insensitive?   😉

 

Please advise.  Thanks.

Alex Craig, General Manager
"Avid Saltwater Fly Fisherman"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 13, 2024 Feb 13, 2024

Copy link to clipboard

Copied

Simple as pie:

ReplaceNoCase(ReplaceNoCase(ReplaceNoCase(ReplaceNoCase( replace( URL, "/", "" ), ".doc", "" ), ".docx", "" ), ".txt", "" ), ".pdf", "" )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 13, 2024 Feb 13, 2024

Copy link to clipboard

Copied

You win the GOLD STAR!!

Thank you very much.

PS  Now that the code is correct the searches process far more quickly than I'd expected.  Both our production (4.51) and development (2023) servers are high end, but the Verity searches on 4.51 are starting to stretch out & both machines are crunching about the same amount of data.

I was concerned about the necessary move to Solr.  Primiarily because of all the necessary code changes. But I'd also seen a number of threads about slow performance.

Looks like I won't have to worry about the size of this collection for awhile.  It flat blazes through the searches.

Alex Craig, General Manager
"Avid Saltwater Fly Fisherman"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 03, 2024 Apr 03, 2024

Copy link to clipboard

Copied

LATEST

A suggestion:

<!--- Use \ to escape ".". The regular-expression match is from left to right, so place docx before doc --->
<cfset resultingString = REReplaceNoCase(theURL, "/|\.docx|\.doc|\.txt|\.pdf", "","all")>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation