takezoe / solr-scala-client

Solr Client for Scala
Apache License 2.0
91 stars 43 forks source link

case classes with empty field #68

Open a-tsioh opened 4 years ago

a-tsioh commented 4 years ago

Thank you for this useful work !

I'm running into a problem when using case class to describe documents. If for one document a text field value is an empty string (""), the document can be stored by Solr but the specific field will not be. Then at query time, the SolrClient seems unable to rebuild the document when I try to getResultsAs[MyCaseClass](...)

It seems to work with Option[String] (with Some("") becoming None though)

takezoe commented 4 years ago

Thanks for reporting. Let me see on this weekend!

takezoe commented 4 years ago

@a-tsioh As long as I tested, Solr (or SolrJ) doesn't allow an empty string for a required string field while we can specify an empty string for optional string fields though these fields are not stored in the document.

Meanwhile, if a field doesn't exist in a document on Solr, solr-scala-client handles it as null. Then it's converted to null for String field or None for Option[String] field. This is an intentional behavior in solr-scala-client end.

I guess the field you tried to store an empty string is optional. Then you should use Option[String] and use None instead of an empty string even when you store documents.