Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add field in solr schema.xml

Tags:

field

solr

I am using solr to make search on my database, and am trying to add a new field (publisher_id of an article) in conf/schema.xml to get the value of the publisher_id after making search on my database, i didn't find any field name equivalent to this field. so how can i add it as a field in schema.xml to be returned with the searched values (body,title,date and publisher_id) of the article?

like image 663
Ruba Avatar asked Jul 13 '11 13:07

Ruba


People also ask

How do I add a new field in Solr schema?

Add the Solr field type definitions to the search index schema, and then use the new type. Add a table column to the index. Add CQL tuple and user-defined type (UDT) columns to an existing search index. Dynamically index CQL map columns or manually set the Solr field type for key.

What are fields in Solr?

The field type defines how Solr should interpret data in a field and how the field can be queried. There are many field types included with Solr by default, and they can also be defined locally.


2 Answers

First of all: what kind of data is stored in publisher_id? If it is a number (int, log) so add an field with the corresponding type, like:

<field name="publisher_id" type="int" indexed="true" stored="true" />

After adding a field to the schema.xml, you have to restart the solr-instance and rebuild your index.

like image 88
The Bndr Avatar answered Sep 28 '22 01:09

The Bndr


Note that dynamic field additions have been added in Solr 4.4 and Solr 5.0...neither of which are yet released.

In the meantime, if you wish to add a field to your index, you have two options. First, you can do the hard way: Add the field to your schema, clear your index, restart Solr and reindex everything. This tends to be a bit untenable.

Alternatively, you can use a dynamic field declaration. If you look in the schema, you'll see lines like these:

<dynamicField name="*_i"  type="int"    indexed="true"  stored="true"/>
<dynamicField name="*_is" type="int"    indexed="true"  stored="true"  multiValued="true"/>

These mean that if you add a field with a name ending in _i or _is, you'll be all set to go. These are usually enabled in the default schema, so if you have flexibility about what to call the field, you might be all set with this.

If neither of those options look promising, your third option is to wait for Solr 4.4 or 5.0 and upgrade (which will also take a reindex in all likelihood!).

like image 39
mlissner Avatar answered Sep 28 '22 02:09

mlissner