How to extend IndexSchema and SchemaField

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

How to extend IndexSchema and SchemaField

Renaud Delbru
  Hi,

I would like to extend the field node in the schema.xml by adding new
attributes. For example, I would like to be able to write:
<field type="myField" myattribute="myvalue"/>
And be able to access myattribute directly from IndexSchema and
SchemaField objects. However, these two classes are final, and also not
very easy to extend ?
Is there any other solutions ?

thanks,
--
Renaud Delbru
Reply | Threaded
Open this post in threaded view
|

Re: How to extend IndexSchema and SchemaField

Renaud Delbru
  Hi,

so I suppose there is no solution. Is there a chance that SchemaField
becomes extensible in the future ? Because, at the moment, all the field
attributes (indexed, stored, etc.) are hardcoded inside SchemaField. Do
you think it is worth opening an issue about it ?
--
Renaud Delbru

On 07/09/10 16:13, Renaud Delbru wrote:

>  Hi,
>
> I would like to extend the field node in the schema.xml by adding new
> attributes. For example, I would like to be able to write:
> <field type="myField" myattribute="myvalue"/>
> And be able to access myattribute directly from IndexSchema and
> SchemaField objects. However, these two classes are final, and also
> not very easy to extend ?
> Is there any other solutions ?
>
> thanks,

Reply | Threaded
Open this post in threaded view
|

Re: How to extend IndexSchema and SchemaField

Javier Diaz
Hi Renaud:

Right now we faced the same issue: while developing a new RequestHandler we
needed to add some information per field (in our case to define some fields
as defaultSearchFields). We thought that this could be added externally in a
configuration file or in the schema as new attributes.

Looking at the code we found out that there's no way to extend the schema.
Finally we copied part of the code that reads the schema in our
RequestHandler. It works but I'm not sure if it's the best way to do it. Let
me know if you want our code as an example.

I do think its worth to open an issue for this requirement.

Regards,

Javier

On Thu, Sep 9, 2010 at 7:29 PM, Renaud Delbru <[hidden email]>wrote:

>  Hi,
>
> so I suppose there is no solution. Is there a chance that SchemaField
> becomes extensible in the future ? Because, at the moment, all the field
> attributes (indexed, stored, etc.) are hardcoded inside SchemaField. Do you
> think it is worth opening an issue about it ?
> --
> Renaud Delbru
>
> On 07/09/10 16:13, Renaud Delbru wrote:
>
>>  Hi,
>>
>> I would like to extend the field node in the schema.xml by adding new
>> attributes. For example, I would like to be able to write:
>> <field type="myField" myattribute="myvalue"/>
>> And be able to access myattribute directly from IndexSchema and
>> SchemaField objects. However, these two classes are final, and also not very
>> easy to extend ?
>> Is there any other solutions ?
>>
>> thanks,
>>
>
>
Reply | Threaded
Open this post in threaded view
|

RE: How to extend IndexSchema and SchemaField

Charlie Jackson
Have you already explored the idea of using a custom analyzer for your
field? Depending on your use case, that might work for you.

- Charlie
Reply | Threaded
Open this post in threaded view
|

Re: How to extend IndexSchema and SchemaField

Renaud Delbru
In reply to this post by Javier Diaz
  Hi Javier,

On 10/09/10 07:15, Javier Diaz wrote:
> Looking at the code we found out that there's no way to extend the schema.
> Finally we copied part of the code that reads the schema in our
> RequestHandler. It works but I'm not sure if it's the best way to do it. Let
> me know if you want our code as an example.
So, do you mean you are duplicating part of the code for reading the
schema and parse on your own way the schema in your request handler ?
If you could share the code to have a look, it could be helpful and
inspiring. cheers.
--
Renaud Delbru
Reply | Threaded
Open this post in threaded view
|

Re: How to extend IndexSchema and SchemaField

Renaud Delbru
In reply to this post by Charlie Jackson
  Hi Charlie,

On 10/09/10 16:11, Charlie Jackson wrote:
> Have you already explored the idea of using a custom analyzer for your
> field? Depending on your use case, that might work for you.
Yes, I have thought of that, or even extending field type. But this does
not work for my use case, since I can have multiple fields of a same
type (therefore with the same field type, and same analyzer), but each
one of them needs specific information. Therefore, I think the only
"nice" way to achieve this is to have the possibility to add attributes
to any field definition.

cheers
--
Renaud Delbru
Reply | Threaded
Open this post in threaded view
|

Re: How to extend IndexSchema and SchemaField

Lance Norskog-2
How about this:

<field name="abc" type="custom">
    <property name="xyz">value</property>
</field>

It generally would be better to keep the attribute space clean and
make it very clear you are doing something unique to this field.

On Fri, Sep 10, 2010 at 9:16 AM, Renaud Delbru <[hidden email]> wrote:

>  Hi Charlie,
>
> On 10/09/10 16:11, Charlie Jackson wrote:
>>
>> Have you already explored the idea of using a custom analyzer for your
>> field? Depending on your use case, that might work for you.
>
> Yes, I have thought of that, or even extending field type. But this does not
> work for my use case, since I can have multiple fields of a same type
> (therefore with the same field type, and same analyzer), but each one of
> them needs specific information. Therefore, I think the only "nice" way to
> achieve this is to have the possibility to add attributes to any field
> definition.
>
> cheers
> --
> Renaud Delbru
>



--
Lance Norskog
[hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: How to extend IndexSchema and SchemaField

Chris Hostetter-3
In reply to this post by Renaud Delbru

: Yes, I have thought of that, or even extending field type. But this does not
: work for my use case, since I can have multiple fields of a same type
: (therefore with the same field type, and same analyzer), but each one of them
: needs specific information. Therefore, I think the only "nice" way to achieve
: this is to have the possibility to add attributes to any field definition.

Right, at the moment custom FieldType classes can specify whatever
attributes they want to use in the <fieldType /> declaration -- but it's
not possible to specify arbitrary attributes that can be used in the
<field /> declaration.

By all means, pelase open an issue requesting this as a feature.

I don't know that anyone explicitly set out to impose this limitation, but
one of the reasons it likely exists is because SchemaField is not
something that is intended to be customized -- while FieldType
objects are constructed once at startup, SchemaField obejcts are
frequently created on the fly when dealing with dynamicFields, so
initialization complexity is kept to a minimum.  

That said -- this definitely seems like that type of usecase that we
should try to find *some* solution for -- even if it just means having
Solr automaticly create hidden FieldType instances for you on startup
based on attributes specified in the <field /> that the corrisponding
FieldType class understands.


-Hoss

--
http://lucenerevolution.org/  ...  October 7-8, Boston
http://bit.ly/stump-hoss      ...  Stump The Chump!

Reply | Threaded
Open this post in threaded view
|

Re: How to extend IndexSchema and SchemaField

Renaud Delbru
  Hi Chris,

I have opened an issue (SOLR-2146 [1]) following that discussion.

[1] https://issues.apache.org/jira/browse/SOLR-2146

cheers
--
Renaud Delbru

On 14/09/10 01:06, Chris Hostetter wrote:

> : Yes, I have thought of that, or even extending field type. But this does not
> : work for my use case, since I can have multiple fields of a same type
> : (therefore with the same field type, and same analyzer), but each one of them
> : needs specific information. Therefore, I think the only "nice" way to achieve
> : this is to have the possibility to add attributes to any field definition.
>
> Right, at the moment custom FieldType classes can specify whatever
> attributes they want to use in the<fieldType />  declaration -- but it's
> not possible to specify arbitrary attributes that can be used in the
> <field />  declaration.
>
> By all means, pelase open an issue requesting this as a feature.
>
> I don't know that anyone explicitly set out to impose this limitation, but
> one of the reasons it likely exists is because SchemaField is not
> something that is intended to be customized -- while FieldType
> objects are constructed once at startup, SchemaField obejcts are
> frequently created on the fly when dealing with dynamicFields, so
> initialization complexity is kept to a minimum.
>
> That said -- this definitely seems like that type of usecase that we
> should try to find *some* solution for -- even if it just means having
> Solr automaticly create hidden FieldType instances for you on startup
> based on attributes specified in the<field />  that the corrisponding
> FieldType class understands.
>
>
> -Hoss
>
> --
> http://lucenerevolution.org/  ...  October 7-8, Boston
> http://bit.ly/stump-hoss      ...  Stump The Chump!
>