简体   繁体   中英

Add field in solr schema.xml

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?

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.

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.).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM