I'm creating a some Solr plugins that index and search documents in a
special way, and I'd like to make them as easy as possible to
configure. Ideally I'd like users to be able to just drop a jar in
place without having to copy any configuration into schema.xml, although
I suppose they will have to register the plugins in solrconfig.xml.
I tried making my UpdateProcessor "core aware" and creating FieldTypes
and SchemaFields in the inform(SolrCore) method. This was a good start,
but I'm running into some issues getting the types properly
initialized. One of my types, for example, derives from TextField, but
this seems to require an initialization pass in order to get its
properties set up properly. What I'm seeing is that my field values
aren't being tokenized, even though I specify TOKENIZED when I create
the SchemaField. I'm beginning to get the feeling I'm doing something
not-quite anticipated by the API designers.
My question is: is there a way to go about doing something like this
that isn't swimming upstream? Should I just give up and require users
to incorporate my schema in the xml config?
Here is a code snippet for anyone willing to dig in a little:
/** Called when each core is initialized; we ensure that lux fields
are configured. */
public void inform(SolrCore core) {
IndexSchema schema = core.getSchema();
Map<String,SchemaField> fields = schema.getFields();
if (fields.containsKey("lux_path")) {
return;
}
Map<String,FieldType> fieldTypes = schema.getFieldTypes();
FieldType luxTextWs = fieldTypes.get("lux_text_ws");
if (luxTextWs == null) {
luxTextWs = new TextField ();
luxTextWs.setAnalyzer(new WhitespaceGapAnalyzer());
luxTextWs.setQueryAnalyzer(new WhitespaceGapAnalyzer());
fieldTypes.put("lux_text_ws", luxTextWs);
}
fields.put("lux_path", new SchemaField ("lux_path", luxTextWs,
0x233, "")); // 0x233 = INDEXED | TOKENIZED | OMIT_NORMS |
OMIT_TF_POSITIONS | MULTIVALUED
fields.put("lux_elt_name", new SchemaField ("lux_elt_name", new
StrField(), 0x231, ""));// INDEXED | OMIT_NORMS | OMIT_TF_POSITIONS |
MULTIVALUED
fields.put("lux_att_name", new SchemaField ("lux_att_name", new
StrField(), 0x231, ""));
// must call this after making changes to the field map:
schema.refreshAnalyzers();
}