Non Case-Sensitive Search

We need to search text fields containing mixed upper and lower case long descriptive information. The database entries are also inconsistent so there is no guarantee that upper case letters appear only at the beginning of a word.

We would like to be able to do a non case-sensitive search effectively BUT at the same time retain how the descriptions were originally keyed in for our reports.

Apart from specifying all possible combinations of upper and lower case for the search, is there anything that will work like an anycase ?

Thanks,
Lorenzo Escalante
Perth W.A.


Listserv Archives (BOB member since 2002-06-25)

Could you have 2 objects? Use 1 for results and 1 for conditions. Make the condition object do something like “lower(text)”. Then you could have your users always use lower case when comparing to this field. You could display the original field.

Just an idea…


Listserv Archives (BOB member since 2002-06-25)

In a message dated 98-09-02 23:16:52 EDT, you write:

We need to search text fields containing mixed upper and lower case long
descriptive information. The database entries are also inconsistent so there is no guarantee that upper case letters appear only at the beginning of a word.

We would like to be able to do a non case-sensitive search effectively BUT at the same time retain how the descriptions were originally keyed in for our reports.

Apart from specifying all possible combinations of upper and lower case for the search, is there anything that will work like an anycase ?

For this example I will assume that the field being searched is a customer name.

There is an interesting trick to this. You could, for example, create an object that uses your database UPPER() command (if available) to force all of the data in the table to be upper case. That would allow your users to search with confidence, knowing that all of the search conditions should be in upper case. This object could be called Search Name. It would be valid as a condition, but not as a result object. You can control these settings when the object is set up in the Designer application.

Next, create an object called Customer Name that can be a result object but cannot be a search object. This object would not use the UPPER() function, and would be used for display purposes on the report.

This should work, but will have a side effect of ruining any chance of using a database index on the customer name column. (If the field in question is not indexed, then this is not a concern.) If the field is indexed,however, then you will lose that performance benefit. To solve that problem, you should go another way.

Instead of using just a search based on the UPPER version of the customer name, it turns out that the following set of conditions are often enough to use the index and search for matches based on the upper case version. If you are searching for a customer named “Brown” then it goes something like this:

(customer_name like 'Br%' OR
customer_name like 'br%' OR
customer_name like 'bR%' OR
customer_name like 'BR%') AND
upper(customer_name) = 'BROWN'

It turns out that specifying all possible case options for the first two letters is enough to narrow down the search using an index, while the last item checks for the exact match. This is, however, not very user friendly! You would not want to train your users to build conditions in this way!

So, the final solution: build an object that picks apart the user’s criteria and builds the condition for them. You did not specify which database you are using, so I’ll provide an example using Oracle. Because it’s the easiest.

The predefined condition would be called ‘Customer Name Search’ and the where clause could be something like:

(
customers.customer_name like
upper(substr(@prompt('Enter customer name','A',,mono,free),1,1) || lower(substr(@prompt('Enter customer name','A',,mono,free),2,1) || '%' OR customers.customer_name like
lower(substr(@prompt('Enter customer name','A',,mono,free),1,1) || lower(substr(@prompt('Enter customer name','A',,mono,free),2,1) || '%' OR customers.customer_name like
lower(substr(@prompt('Enter customer name','A',,mono,free),1,1) || upper(substr(@prompt('Enter customer name','A',,mono,free),2,1) || '%' OR customers.customer_name like
upper(substr(@prompt('Enter customer name','A',,mono,free),1,1) || upper(substr(@prompt('Enter customer name','A',,mono,free),2,1) || '%' ) AND upper(customers.customer_name) =
upper(@prompt('Enter customer name','A',,mono,free)) 

In this example, I am not using a list of values for customer names. It probably is not necessary, as the user is simply expected to type in the name. If you are going to use the list of values feature, then this trick is not required as you will have an exact match. Note: be very careful with the parenthesis! You have to have the four “OR” conditions inside parenthesis, and the AND condition outside.

(test 1 OR test 2 OR test 3 OR test 4) AND test 5 

Recall that if you use the same prompt over and over, then BusObj will only prompt the user one time, ensuring that the same value is used throughout the logic for the entire condition. As I said, this object should work for Oracle; as long as your database has an equivalend Sub String, Upper, and Lower function then you should be able to convert this idea to work.

Hope this helps!

Regards,
Dave Rathbun
Integra Solutions
www.islink.com

PS - As a side note… thanks to everyone that attended the user conference that came up and introduced themselves. It is always great to put a face with the names on the list!


Listserv Archives (BOB member since 2002-06-25)

To get a Case-Insensitive search, you can define the object as follows:

Select Clause: Table.Object
Where Clause: TO_UPPER(Table.Object) inlist (TO_UPPER(@Prompt(‘What Values Would you like?’,A,’’,multi,free)))

This will essentially convert all of your Entries to UpperCase and compare them to the same values on the database (as if they were all in UpperCase as well). The RESULTING VALUES, however, should retain their original format from the database.

I apologize if the syntax is not correct, but I am running a couple of days without sleep, so I am just trying to get the gist of the solution out there. This also works for any of the ‘conversions’ (lower, upper, or InitCap). Thanks!

-rm


Listserv Archives (BOB member since 2002-06-25)

Robert (digpen@EARTHLINK.NET) wrote:

To get a Case-Insensitive search, you can define the object as follows:

Select Clause: Table.Object
Where Clause: TO_UPPER(Table.Object) inlist (TO_UPPER(@Prompt(‘What Values Would you like?’,A,‘’,multi,free)))

Although this will technically work, if you have a choice I’d recommend against applying functions directly to fields in a table. Since the objects you are talking about would be placed in the “WHERE” clause, they are strong potential candidates for database indexes. However, even if an index is added, if a function is used on the table column the optimizer will never take advantage of it.

The alternative requires a little backend work in the database. You need to insure that you have a field in a table containing the value they need completely in uppercase or lowercase. If mixed case is a requirement, this may require creating a separate field. If not, the program responsible for sourcing the data should be able to just convert it to upper/lowercase. Assuming this requires a new field, you would now have a table that includes the following two fields:

Table.ObjectMC - Contains the mixed case text Table.ObjectUC - Containst the text all in uppercase
(you could use lowercase alternately)

Then, you apply the function in your where clause ONLY on the prompt value or constant be provided locally. As a result, your where clause would become:

Where Clause: Table.ObjectUC inlist
(TO_UPPER(@Prompt(‘What Values Would you like?’,A,‘’,multi,free)))

This will simply apply the function on the locally provided constant(s) and not negate the potential use of an index. The index may not matter if the table small or the column in question has a low cardinality. However, it is something to watch out for.

FYI,

Bob Molby
GE Lighting


Listserv Archives (BOB member since 2002-06-25)

Hi there,
I just tried all the options and what I get is:
Parse failed: Exception DBD, ORA-00907 missing right parenthesis State: N/A
:nonod:

UPPER(table.object) in (UPPER(@Prompt(‘What Values Would you like?’,A,‘LOV\objectname’,multi,free)))

any suggestions?

Thanks,
NM


vatrbaby (BOB member since 2004-11-03)

What happens when you try:

UPPER (table.object) = UPPER ( @Prompt('What Values Would you like?', A, 'LOV\objectname', MONO, free) )

See also this thread (UPPER function with MULTI parameter in @Prompt will cause SQL syntax error).


Andreas :de: (BOB member since 2002-06-20)

same !!! :wah:


vatrbaby (BOB member since 2004-11-03)

Hi,
I have seen that the following works, but it works only when the input has a single value … but it won’t work with multiple values inputs…

here is the syntax

UPPER(table.column) in (UPPER(@prompt(‘Select value(s) or enter NONE’,‘A’,multi,free)))

Any suggestions?

Thanks in advance!


vatrbaby (BOB member since 2004-11-03)