How to search parentheses, brackets using FULL TEXT INDEXING - sql-server-2008-r2

I have been fighting this issue for a while
I would like to use a FULL Text Seach query to find Files on a windows file system.
The problem is when the case comes up where there is a parentheses in the file name.
This example was created from a copy being pasted in the same location as the original a few times.
Here is my code:
DECLARE #SearchWord VARCHAR(50)
SET #SearchWord = '"KAP1556PP_P01(2).jpg"'
SELECT
[FileName],
[FilePath]
FROM
[dbo].[tblLegalPlan]
WHERE
CONTAINS(*, #SearchWord)
When I use Double quotes for the #Searchword I recieve no results.
When I use no quotes for the #Searchword I recieve an error message:
Msg 7630, Level 15, State 2, Line 8
Syntax error near '(' in the full-text search condition 'KAP1556PP_P01(2).jpg'.
When I search for files containing TEXT up to the bracket i Get undesrired results obviously:
SET #SearchWord = '"KAP1556PP_P01*"'
Results
FileName FilePath
KAP1556PP_P01(1).jpg BC\EPP\KAP
KAP1556PP_P01(2).jpg BC\EPP\KAP
Any and all iterations of the above show to not be usefull.
There are many articles of people trying to parse the search terms and work it out, but I have not come accross any that can handle this situation.
A solution would be appreciated.
Thanks

The work around to this for me was to execute a Stored Procedure that would remove and/or replace the brackets in question, allowing the FULL TEXT indexing to work.

Related

Is there any way to prevent or detect char(0) from texts?

In some occasions, specially when copy-pasting, we end up having some text fields with a character 0 (nul) at the end of a string.
It doesn't show in any way when you display the data, but you do detect it when you export it.
We've tried to (at least) detect it by using the "Position" function.
However Position(text_field, char(0), 1, 1) won't find this char (it does return 0, even if the character is there).
I guess this is some kind of bug from FileMaker, but I'd like to know if anyone has found a way to circumvent it...
More info and a database sample at: https://community.claris.com/en/s/question/0D53w00005wrUMMCA2/character-0-0x0-in-text-fields
Unfortunately, the result of Char(0) is an empty string, not the expected control character.
You can generate the null character in a number of ways:
HexDecode ( "00" )
Base64Decode ( "AA==" )
ExecuteSQL ( "SELECT DISTINCT CHR(0) FROM SomeTable" ; "" ; "" )
or paste it into a global field and get it from there.
Once you have the character, it's easy to detect it or just substitute it out.
You may want to bypass the entire issue by allowing only printable characters - see, for example: https://www.briandunning.com/cf/1291
I run into this problem quite frequently when users try to copy-paste text from office programs into FileMaker fields on windows (my guess is that FileMaker for some reason can't handle Microsoft Office line endings properly).
The most efficient solution I found is to use auto enter calculation or script with Filter() function, in order to remove any unwanted characters.
Alterntively if you have access to plug-ins you can try using the MBS ("Text.RemoveControlCharacters") function from Monkeybread FileMaker plug-in which is uspposed to remove all characters with code 32 or lower.

postgresql fulltext returning wrong results

I'm using postgresql full text tsvector column.
But I found a problem:
When I search for "calça"
The results contains the following results:
1- calça red
2- calça blue
3- calçado red
Why "calçado" is being returned when I search for "calça" ?
Is there any configuration so I can solve this?
Thanks.
It isn't just a matter that one string contains the other. The Portuguese stemmer thinks this is the way they should be stemmed. If you turn the longer word into 'calçadot', for example, it no longer stems it, because (presumably) 'adot' is not recognized as a Portuguese suffix which ought to be removed the way 'ado' is.
If you don't want stemming at all, then you could change the config to 'simple', which doesn't stem. But at that point, maybe you don't want full text search at all, and could just use LIKE instead with a pg_trgm index.
If it is just this particular word that you don't want stemmed, I think you can set up a synonym dictionary which will map calçado to itself, which will bypass stemming.

Capture File name from File Browser Item Field in Oracle Apex

I want to capture file_name and store it in another item field at run time using dynamic action.
I tried it to capture File Browser Item field but its capturing entire file path.
Please suggest if this can be done using PLSQL or JS in Oracle Apex 4.2
You can use regular expression, relying on the fact that there is always a backslash before the filename:
$('#P6_FILE').val().match(/\\([^\\]*)$/)[1]
explaining the regular expression:
\\ double backslash: escaping the backlash
() parenthesis to dig out the filename from the result that initially includes backslashes
[^\\]* any letter that is not a backslash, as many times as you'd like
$ end of string
Stackoverflow sometimes escapes backslashes itself, so this might look messy
$('#P6_FILE').val().match(/\([^\]*)$/)[1]
this has worked in DA set value
I use this SQL to get the file name from the file browser :
select filename
FROM apex_application_temp_files
where name = :P2_FILE_SELECT;
P2_FILE_SELECT is the file browser item.
Write this SQL into "SQL Query" of SOURCE.

PostgreSQL Trimming Leading and Trailing Characters: = and "

I'm working to build an import tool that utilizes a quoted CSV file. However, several of the fields in the CSV file are reported as such:
"=""38000"""
Where 38000 is the data I need. The data integration software I use (Talend 6.11) already strips the leading and trailing double quotes for me (so, "38000" becomes 38000), but I can't find a way to get rid of those others.
So, essentially, I need "=""38000""" to become "38000" where the leading "=" is removed and the trailing "" is removed.
Is there a TRIM function that can accomplish this for me? Perhaps there is a method in Talend that can do this?
As the other answer stated, you could do that operation in SQL. Or, you could do it in Java, Groovy, etc, within Talend. However, if there is an existing Talend component which does the job, my preference is to use it. That leads to faster development, potentially less testing, and easier maintenance. Having said that, it is important to review all the components which are available, so you know what's available to you.
You can use the Talend component tReplace, to inspect each of the input columns you want to trim of quotes and equal signs. A single tReplace component can do search and replace operations on multiple input columns. If all the of the replaces are related to each other, I would keep them within a single tReplace. When it gets to the point of doing unrelated replacements, I might place those within a new tReplace so that logical operations are organized and grouped together.
tReplace
For a given Input Column
search for "=", replace with ""
search for "\"", replace with ""
Something like that:
SELECT format( '"%s"', trim( both '"=' from '"=""38000"""' ) );
-[ RECORD 1 ]---
format | "38000"
1st: trim() function removes all " and = chars. Result is simply 38000
2nd: with format can add double quote back to get wishful end result
Alternatively, can use regexp and other Postgres string functions.
See more:
https://www.postgresql.org/docs/current/static/functions-string.html

Dollar sign in text when passing variable

I got stricky/old php code, I just try to clean it , fix some bugs, and so on. Also the server uses php 4 too.
The problem is the following:
I get some data back from the database, I work with those data and show them. If the result contains a dollar sign, the PHP try to handle it as a variable.
For example :
$result = $this->sqlresult('SELECT * From Tablename where id=15');
$details = $result['description'];
echo $details;
Let me show an example what's happening , when the $result['description'] contains any wrong text, like 'This book is available for $148':
It usually doesn't show anything or show a wrong text , like This book is available for 48.
I have tried a preg replace functions on the details, I was looking for char changes , or html_special_chars , and tried those too, but nothing happened or not the original text came up.
preg_replace('/\$ /','/&#36/;' $details);
I know , that the double quotes on passing variables causes a similar error. I checked this topic too, but it wasn't a solution for me.
Current solution is just adding an extra space between the price amount the $ sign, but I am looking for a better one.
preg_replace('/\$/','/\$ /' $details);
Have you tried to use escape characters? This book is \$148.