Reputation: 67
I am working with solr. in database indexing is there a way i can give default value to a field in data config file itself. I cannot give the default value in schema.xml because my value depends on table so it has to be done in data config file.
Upvotes: 2
Views: 1646
Reputation: 2360
Yes, it is possible.
You have to specify the default value in the schema.xml file. For example,
<field name="myFileWithDefaultValue" type="string" stored="true" indexed="true" default="default_value_string_here"/>
Reference:
Upvotes: 2
Reputation: 52789
You can add it to the sql query itself.
And as you would know the table you are firing the query on when defining the entity, the value can be changed.
select 'Annual' as datatype, i.* from item i
And field type defination -
<field column="datatype" name="datatype" />
Upvotes: 1
Reputation: 13394
If you indexing as database - by using data import handler, you could use MySQL features to return an default value, if the filed is (for example) empty.
You could use the IFNULL
or CASE
. Look at this: http://dev.mysql.com/doc/refman/5.1/en/control-flow-functions.html
An other way is to use UNION
on MySQL: http://dev.mysql.com/doc/refman/5.1/en/union.html
COALESCE
is also an option: http://dev.mysql.com/doc/refman/5.1/en/comparison-operators.html#function_coalesce
Upvotes: 2