The field value is 1 or true in solr search results
I have one field that is indexed as string in Solr's schema.xml, which is from a boolean(tinyint) column in mysql database.开发者_开发百科
In query, I search against this field using 1. But without any change, this query cannot return correct results as it did. After I used true instead of 1, it worked again. Now it goes wrong again but with true, no problem with 1.
What's the exact problem here? Do I need change the field type in schema.yml to integer?
Thank you in advance.
Since it's a string field, we can't possibly know how you indexed it. It could be "true" / "false" or "1" / "0" or "on" / "off", etc. Or even a mix of these, maybe you have some documents with "true" and some with "1".
If it's semantically a boolean field I recommend using the boolean fieldType, e.g.:
<field name="inStock" type="boolean" indexed="true" stored="true" />
for this to work you need the boolean fieldType declared (it comes declared in the default schema):
<fieldType name="boolean" class="solr.BoolField" sortMissingLast="true" omitNorms="true"/>
Remember to rebuild the index after this change.
精彩评论