0

I need to query a database of products, the query can contains forward slash like "30/20", but it always splits the query in two parts as _text: 30 and _text: 20.

I tried to escape the forward slash with a back slash like this "30/20" or to use encodeURI as "30%2F20" but it does not work either.

Shall I encode/replace the forward slash in the database?

I tried with quotes following (Solr Query not parsing forward slash) like "5/12" in the query field, it's not working if I have "12.5/12" in the database.

Anyone had the issue? Thanks in advance!

Emile
  • 21
  • 1
  • 3

1 Answers1

0

Use a different tokenizer that doesn't split on /, such as the WhitespaceTokenizer. That way 5/12 will be kept as one, single token.

If you still need to support people querying for 5 12 to give a hit as well, that would be served by the original field type. If you need to support querying by a subset of the complete token as well (i.e. 5/12 when the value is 12.5/12), use an NGramFilter to split the token further into subtokens covering every combination (1, 12, 12.5, etc.).

MatsLindh
  • 49,529
  • 4
  • 53
  • 84