2

I'm using solr for the search functionality on my webapp. I append an "*" to the end of each user's search. So, if the search is: foo I change it to filename:foo*

This works fine, except that often a hyphen will be included in the user's search. A search of filename:foo-bar* returns zero results, as the hyphen removes any search results produced from the search term(s) after it. I can escape it, as filename:foo\-bar* but I still get zero results. If I try filename:foo"-"* the search returns all documents.

Any suggestions on how to get - and * to play nice with one another?

Thanks for the help

Mike Nitchie
  • 1,166
  • 2
  • 13
  • 29
  • Try switching from _text_ type to **solr.StrField** type, and issue a `filename:foo-bar*` search. – rchukh Oct 18 '13 at 18:34
  • 1
    That solves the problem in the post. However, it requires the query to be case sensitive. Any suggestions for how to get around that? – Mike Nitchie Oct 18 '13 at 19:03
  • Following the response in [this question](http://stackoverflow.com/a/2060960/935083) for creating case insensitive string type - it seems to work fine locally on test data. – rchukh Oct 18 '13 at 19:10

1 Answers1

1

In my experience, I've had to escape the wildcard character if anything else in the string is escaped. This is to get it to function as a wildcard; you'd think it'd make it look for the character itself, but it seems not to. Note: Escaping the * without other escaped characters seems to search exactly for the character *, and does not use it as a wildcard operator.

field:*and\/or* //would NOT perform a wildcarded search for "and/or"

field:\*and\/or\* //would perform wildcard search for and/or

To be clear, it seems like they are backwards, but that is what hass worked in my cases.

Will Bonde
  • 560
  • 6
  • 19