I should also correct myself further here... After adding more "whitespace" test cases this afternoon, (it seems last Friday, I only added a test for exact name with a whitespace), it appears whitespace+wildcard+case insensitive searches of ANY type fail. I am really hoping to get this whitespace thing figured out soon.

H. Wilson

On 08/27/2010 03:06 PM, H. Wilson wrote:
OK, well I got the spaces part figured out, and will post it for anyone who needs it. Putting quotes around the spaces unfortunately did not work. During testing, I determined that if you performed the following query for the exact fullName property:

filter.addContains ( @fullName, '"+Text.escapeIllegalXpathSearchChars(".North.South.East.West Land"));

It would return nothing. But tweak it a little and add a wildcard, and it would return results:

   filter.addContains ( @fullName,
   '"+Text.escapeIllegalXpathSearchChars(".North.South.East.West Lan*"));

But since I did not want to throw in wild cards where they might not be wanted, if a search string contained spaces, did not contain wild cards and the user was not concerned with case sensitivity, I used the fn:lower-case. So I ended up with the following excerpt (our clients wanted options for case sensitive and case insensitive searching) .

public OurParameter[] getOurParameters (boolean performCaseSensitiveSearch, String searchTerm, String srchField ) { //srchField in this case was fullName

   .....

   if ( performCaseSensitiveSearch) {

       //jcr:like for case sensitive
filter.orJCRExpression ("jcr:like(@" + srchField +", '"+Text.escapeIllegalXpathSearchChars (searchTerm)+"')");

   }
   else {

       //only use fn:lower-case if there is spaces, with NO wild cards

if ( searchTerm.contains (" ")&& !searchTerm.contains ("*")&& !searchTerm.contains ("?") ) {

filter.addJCRExpression ("fn:lower-case(@"+srchField+") = '"+Text.escapeIllegalXpathSearchChars(searchTerm.toLowerCase())+"'");

       }

       else {

           //jcr:contains for case insensitive
filter.addContains ( srchField, Text.escapeIllegalXpathSearchChars(searchTerm));

       }

   }
   ....

}


Hope that helps anyone who needs it.

H. Wilson

OK so it looks like I have one other issue. Using the configuration as
posted below and sticking to my previous examples, with the addition of one
with whitespace. With the following three in our repository:

   .North.South.East.WestLand
   .North.South.East.West_Land
   .North.South.East.West Land    //yes that's a space

...using a jcr:contains, with exact name search with NO wild cards: the
first two return properly, but the last one yields no result.

   filter.addContains(@fullName,
'"+org.apache.jackrabbit.util.Text.escapeIllegalXpathSearchChars(".North.South.East.West
Land") +"'));
I think the space in a contains is seen as an AND by the
Jackrabbit/Lucene QueryParser. I should test this however as I am not
sure. Perhaps you can put quotes around it, not sure if that works
though

Regards Ard

According to the Lucene documentation, KeywordAnalyzer should be creating one token, plus combined with escaping the Illegal Characters (i.e. spaces),
shouldn't this search work? Thanks again.

H. Wilson

Reply via email to