You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Fouad Mardini <f....@gmail.com> on 2009/03/04 18:24:28 UTC

Custom Field Type

Hello,

I have a multivalued field in my schema of type text_ws, values are of the
form #int #int
I need to be able to query on the first and sort on the second, this does
not seem to be enabled out of the box
I looked around for a while and it seems the recommended approach is to
create a custom field type and implement this logic in the getSortField
method
But since the field is multivalued, I need to sort by the value i am
searching for, so i need access to the current query being executed.
Also, i can't seem to figure out the correct -classpath to give to javac for
it to find the packages needed to create the class file (my java is a bit
rusty to say the least)

Thanks,
Fouad

Re: Custom Field Type

Posted by Chris Hostetter <ho...@fucit.org>.
: But actually, something like that only works for text field types that
: you can specify an analyzer for.  To sort by the integer value, you
: need an integer field.

we should really fix that so any FieldType can have an analyzer and treat 
Tokens produced just like multivalued fields are right now.

(I remember breifly looking into it a while back and got frustrated 
because i couldn't figure out where in the code the limitation was.)




-Hoss


Re: Custom Field Type

Posted by Yonik Seeley <yo...@lucidimagination.com>.
On Thu, Mar 5, 2009 at 4:50 AM, Fouad Mardini <f....@gmail.com> wrote:
> Thanks for your help, but I am not really sure I follow.
> It is possible to use the PatternTokenizerFactory with pattern = (\d+)  and
> group = 0 to tokenize the input correctly
> But I don't see how to use the copyField to achieve sorting
>
> <copyField source="myfield" destination="dynamic_#{value of second token}"
> />
> I read the documentation and this does not seem to be possible

copyField myfield -> myfield2
the field type for myfield would keep the first number
the field type for myfield2 would keep the second number

But actually, something like that only works for text field types that
you can specify an analyzer for.  To sort by the integer value, you
need an integer field.

So is there a way for your indexing code to split the numbers before
they are sent to Solr?

> Are there any performance implications on using dynamic fields?
> Could you please elaborate on your idea

Very little to none in most situations.

-Yonik
http://www.lucidimagination.com

Re: Custom Field Type

Posted by Fouad Mardini <f....@gmail.com>.
Hello Yonik,

Thanks for your help, but I am not really sure I follow.
It is possible to use the PatternTokenizerFactory with pattern = (\d+)  and
group = 0 to tokenize the input correctly
But I don't see how to use the copyField to achieve sorting

<copyField source="myfield" destination="dynamic_#{value of second token}"
/>
I read the documentation and this does not seem to be possible

Are there any performance implications on using dynamic fields?
Could you please elaborate on your idea

Thanks again
/Fouad


On Wed, Mar 4, 2009 at 8:12 PM, Yonik Seeley <yo...@lucidimagination.com>wrote:

> On Wed, Mar 4, 2009 at 12:24 PM, Fouad Mardini <f....@gmail.com>
> wrote:
> > I have a multivalued field in my schema of type text_ws, values are of
> the
> > form #int #int
> > I need to be able to query on the first and sort on the second, this does
> > not seem to be enabled out of the box
>
> Can you put the two numbers in separate fields for this purpose?
> If you can't do it from the indexer, a schema with copyField in
> conjunction with PatternTokenizerFactory could do it.
>
> -Yonik
> http://www.lucidimagination.com
>

Re: Custom Field Type

Posted by Yonik Seeley <yo...@lucidimagination.com>.
On Wed, Mar 4, 2009 at 12:24 PM, Fouad Mardini <f....@gmail.com> wrote:
> I have a multivalued field in my schema of type text_ws, values are of the
> form #int #int
> I need to be able to query on the first and sort on the second, this does
> not seem to be enabled out of the box

Can you put the two numbers in separate fields for this purpose?
If you can't do it from the indexer, a schema with copyField in
conjunction with PatternTokenizerFactory could do it.

-Yonik
http://www.lucidimagination.com