I am trying to run an FTSearch query on a database using Java. Here is my current code:
String strFTQuery = “( FIELD FORM = " + formName + " )”;
strFTQuery += " AND ( FIELD " + fORG + " = "" + strOrg + “" )”;
DocumentCollection dc = db.FTSearch( strFTQuery );
This syntax partially works correctly. It DOES pull the data I need but it also pulls additional data that I don’t need. For example, say I have an organizational structure of ABC, ABC1, ABC2, ABC-1, ABC-2. If I run this query with strOrg = ABC, I retrieve all the documents associated to ABC, ABC-1 and ABC-2. If I run the query on all the individual organizations, it works fine. It appears to only be a problem if there is an organization with a dash afterwards and I try to search on the higher organizational level. I don’t want this! If I choose to search on ABC, I ONLY want ABC’s documents, NOT ABC-1 nor ABC-2. Is there a way to search for EXACTLY ABC?!? Here are the partial query strings I have tried:
…CONTAINS “ABC”…
…CONTAINS ABC…
…CONTAINS “(ABC)”…
…CONTAINS (ABC)…
…= “ABC”… (current code above)
…= ABC…
…= “(ABC)”…
…= (ABC)…
Any help is appreciated!! Thanks in advance!
Subject: FTSearch Query not working how I want…
The “=” part of the query is “contains”, not “equals”. “ABC-1” contains “ABC”. You would need to specifically exclude the hyphen in your query.
Subject: RE: FTSearch Query not working how I want…
I’m not sure I am understanding what you are saying. I should use CONTAINS instead of the equals sign? If so, how do I exclude other organizations that include the ABC string? For example, wouldn’t …CONTAINS ABC… pull ABC, ABC1, ABC2, ABC-1 and ABC-2? And how do I exclude a hyphen?
Subject: RE: FTSearch Query not working how I want…
The equals sign means the same thing as contains in an FTSearch query. It doesn’t matter which one you use. You do need to add a != or “DOES NOT CONTAIN” clause to exclude the hyphen if you don’t want ABC-1, ABC-2, etc., when you ask for things that contain ABC.
Subject: RE: FTSearch Query not working how I want…
Sorry to be making this so difficult but I tried adding a DOES NOT CONTAIN clause to exclude the hyphen and it still pulls in the extraneous data. If I try using != then I get a ‘query not understandable’ error message. Using the DOES NOT CONTAIN clause, here is what I have: (maybe you can tell me if I am doing something wrong)
(( FIELD FORM = frmAssignment ) AND ( FIELD OrganizationTX CONTAINS “ABC” ) AND ( FIELD OrganizationTX DOES NOT CONTAIN “-” ))
That is the full query string that is being passed to the FTSearch function. This query string still pulls data from ABC, ABC-1 and ABC-2. Am I constructing it incorrectly?
By the way, thanks for all the help an attention you are giving this. It is truly appreciated!!
Subject: RE: FTSearch Query not working how I want…
S’alright – you’re getting there. Try FIELD Organization CONTAINS “ABC” AND FIELD Organization DOES NOT CONTAIN “ABC-”.
Subject: RE: FTSearch Query not working how I want…
I just tried that and it still pulls the data with hyphens. I even tried putting in the exact organization name I DIDN’T want it to pull and it still did. Is there a statement I can use instead of CONTAINS like EXACT MATCH or something?
Thanks again.
Subject: RE: FTSearch Query not working how I want…
No.
Subject: RE: FTSearch Query not working how I want…
Haha! Thanks. I think I’m going to generate a new query that says something like:
( FIELD Function = FTSearch AND FIELD whatShouldIDo = “Never Work Right” )
and see if that does anything.
Subject: FOUND A SOLUTION!!
Finally, I found a solution and the answer was right in front of me the whole time. Stan, I appreciate all the help you gave and you were partially correct in your responses. Here is my final WORKING query string:
(( FIELD FORM = formName ) AND ( FIELD fieldName EQUALS “ABC” AND NOT “ABC-” ))
Thanks again for all your help Stan!
Subject: RE: FTSearch Query not working how I want…
For reference to anyone else digging up this thread (and those in this thread who may be interested):
The FT operator “=” DID used to mean “exactly”, something completely different than its current meaning, which is equivalent to “contains”. This change was made in a later R5 update due to a new GTR search engine (5.08+ I believe?)
Unfortunately there is now NO way to FTSearch for text data that “exactly matches” a string without first knowing about all possible partial-match strings you don’t want.