You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@lucenenet.apache.org by André Maldonado <an...@gmail.com> on 2009/11/06 20:24:55 UTC

Multi-valued fields

Hi all.

There's a way to create a multi-valued field in Lucene.net? Something like?

Field f = new Field("categories", "", Field.Store.YES,
Field.Index.ANALYZED);
f.AddValue("baby")
f.AddValue("black cat")
f.AddValue("brown horse")

Thank's

"Então aproximaram-se os que estavam no barco, e adoraram-no, dizendo: És
verdadeiramente o Filho de Deus." (Mateus 14:33)

Re: Multi-valued fields

Posted by Artem Chereisky <a....@gmail.com>.
Sorry, hit the Send button too early...

foreach (var value in fieldValues)
{
        var fld = new Field("SomeName", value,
Field.Store.NO/YES<http://field.store.no/YES>,
Field.Index.TOKENIZED/UN_TOKENIZED);
       doc.Add(fld);
}

In the code above the name is the same, only the value changes.

There are a couple of things you need to know:

1. For the purposes of search, the code above is the same as
var fld = new Field("SomeName SomeName SomeName SomeName SomeName", value,
Field.Store.NO/YES <http://field.store.no/YES>, Field.Index.TOKENIZED);
provided you use a whitespace or any other tokenizer that treats whitespace
as a token separator. It's important to know this if you are planning to use
SpanQuery where position of terms makes a difference

2. I mainly use the method for fields that are not tokenized to save index
time on tokenization.

my 2c worth...

Art




On Mon, Nov 9, 2009 at 3:11 PM, Artem Chereisky <a....@gmail.com>wrote:

> This is how you do it:
>
> foreach (var value in fieldValues)
> {
>         var fld = new Field("SomeName", value, Field.Store.NO/YES,
> Field.Index.TOKENIZED/UN_TOKENIZED);
>         doc.Add(fld);
> }
>
> There are a couple of things you need to know:
>
>
>
>
>
> On Mon, Nov 9, 2009 at 12:52 PM, Sean Carpenter <st...@gmail.com>wrote:
>
>> That's all there is to it.  Add a field multiple times with the same
>> name and all of the values will be searchable.
>>
>> Sean Carpenter
>>
>> On Sun, Nov 8, 2009 at 7:26 PM, Michael Garski <mg...@myspace-inc.com>
>> wrote:
>> > I've not done it, but I believe you can just add another field with the
>> same
>> > name. The process of appending the second value for the field happens
>> > internally. Check the javadocs for 2.4 under the Document.Add method
>> where
>> > the field is added to the document to confirm.
>> >
>> > Michael
>> >
>> > On Nov 7, 2009, at 3:37 AM, André Maldonado <an...@gmail.com>
>> > wrote:
>> >
>> >> Hi Nitin. Understood, but how I do it?
>> >>
>> >> What method I have to use to add multiple values?
>> >>
>> >> Thank's
>> >>
>> >> "Então aproximaram-se os que estavam no barco, e adoraram-no, dizendo:
>> És
>> >> verdadeiramente o Filho de Deus." (Mateus 14:33)
>> >>
>> >>
>> >> On Sat, Nov 7, 2009 at 03:13, Nitin Shiralkar
>> >> <ni...@coreobjects.com>wrote:
>> >>
>> >>> Yes, you can add multiple values using same field name and all the
>> values
>> >>> would get indexed. So your searches would work fine. However since you
>> >>> are
>> >>> storing the field, you need to remember that Lucene will only return
>> last
>> >>> value indexed under that field. If you intend to retrieve all values,
>> >>> then
>> >>> you can consider adding a dummy field with all values concatenated
>> >>> together.
>> >>>
>> >>>
>> >>> -----Original Message-----
>> >>> From: André Maldonado [mailto:andre.maldonado@gmail.com]
>> >>> Sent: Saturday, November 07, 2009 12:55 AM
>> >>> To: lucene-net-user@incubator.apache.org
>> >>> Subject: Multi-valued fields
>> >>>
>> >>> Hi all.
>> >>>
>> >>> There's a way to create a multi-valued field in Lucene.net? Something
>> >>> like?
>> >>>
>> >>> Field f = new Field("categories", "", Field.Store.YES,
>> >>> Field.Index.ANALYZED);
>> >>> f.AddValue("baby")
>> >>> f.AddValue("black cat")
>> >>> f.AddValue("brown horse")
>> >>>
>> >>> Thank's
>> >>>
>> >>> "Então aproximaram-se os que estavam no barco, e adoraram-no, dizendo:
>> És
>> >>> verdadeiramente o Filho de Deus." (Mateus 14:33)
>> >>>
>> >
>>
>
>

Re: Multi-valued fields

Posted by Artem Chereisky <a....@gmail.com>.
This is how you do it:

foreach (var value in fieldValues)
{
        var fld = new Field("SomeName", value, Field.Store.NO/YES,
Field.Index.TOKENIZED/UN_TOKENIZED);
        doc.Add(fld);
}

There are a couple of things you need to know:




On Mon, Nov 9, 2009 at 12:52 PM, Sean Carpenter <st...@gmail.com>wrote:

> That's all there is to it.  Add a field multiple times with the same
> name and all of the values will be searchable.
>
> Sean Carpenter
>
> On Sun, Nov 8, 2009 at 7:26 PM, Michael Garski <mg...@myspace-inc.com>
> wrote:
> > I've not done it, but I believe you can just add another field with the
> same
> > name. The process of appending the second value for the field happens
> > internally. Check the javadocs for 2.4 under the Document.Add method
> where
> > the field is added to the document to confirm.
> >
> > Michael
> >
> > On Nov 7, 2009, at 3:37 AM, André Maldonado <an...@gmail.com>
> > wrote:
> >
> >> Hi Nitin. Understood, but how I do it?
> >>
> >> What method I have to use to add multiple values?
> >>
> >> Thank's
> >>
> >> "Então aproximaram-se os que estavam no barco, e adoraram-no, dizendo:
> És
> >> verdadeiramente o Filho de Deus." (Mateus 14:33)
> >>
> >>
> >> On Sat, Nov 7, 2009 at 03:13, Nitin Shiralkar
> >> <ni...@coreobjects.com>wrote:
> >>
> >>> Yes, you can add multiple values using same field name and all the
> values
> >>> would get indexed. So your searches would work fine. However since you
> >>> are
> >>> storing the field, you need to remember that Lucene will only return
> last
> >>> value indexed under that field. If you intend to retrieve all values,
> >>> then
> >>> you can consider adding a dummy field with all values concatenated
> >>> together.
> >>>
> >>>
> >>> -----Original Message-----
> >>> From: André Maldonado [mailto:andre.maldonado@gmail.com]
> >>> Sent: Saturday, November 07, 2009 12:55 AM
> >>> To: lucene-net-user@incubator.apache.org
> >>> Subject: Multi-valued fields
> >>>
> >>> Hi all.
> >>>
> >>> There's a way to create a multi-valued field in Lucene.net? Something
> >>> like?
> >>>
> >>> Field f = new Field("categories", "", Field.Store.YES,
> >>> Field.Index.ANALYZED);
> >>> f.AddValue("baby")
> >>> f.AddValue("black cat")
> >>> f.AddValue("brown horse")
> >>>
> >>> Thank's
> >>>
> >>> "Então aproximaram-se os que estavam no barco, e adoraram-no, dizendo:
> És
> >>> verdadeiramente o Filho de Deus." (Mateus 14:33)
> >>>
> >
>

Re: Multi-valued fields

Posted by Sean Carpenter <st...@gmail.com>.
That's all there is to it.  Add a field multiple times with the same
name and all of the values will be searchable.

Sean Carpenter

On Sun, Nov 8, 2009 at 7:26 PM, Michael Garski <mg...@myspace-inc.com> wrote:
> I've not done it, but I believe you can just add another field with the same
> name. The process of appending the second value for the field happens
> internally. Check the javadocs for 2.4 under the Document.Add method where
> the field is added to the document to confirm.
>
> Michael
>
> On Nov 7, 2009, at 3:37 AM, André Maldonado <an...@gmail.com>
> wrote:
>
>> Hi Nitin. Understood, but how I do it?
>>
>> What method I have to use to add multiple values?
>>
>> Thank's
>>
>> "Então aproximaram-se os que estavam no barco, e adoraram-no, dizendo: És
>> verdadeiramente o Filho de Deus." (Mateus 14:33)
>>
>>
>> On Sat, Nov 7, 2009 at 03:13, Nitin Shiralkar
>> <ni...@coreobjects.com>wrote:
>>
>>> Yes, you can add multiple values using same field name and all the values
>>> would get indexed. So your searches would work fine. However since you
>>> are
>>> storing the field, you need to remember that Lucene will only return last
>>> value indexed under that field. If you intend to retrieve all values,
>>> then
>>> you can consider adding a dummy field with all values concatenated
>>> together.
>>>
>>>
>>> -----Original Message-----
>>> From: André Maldonado [mailto:andre.maldonado@gmail.com]
>>> Sent: Saturday, November 07, 2009 12:55 AM
>>> To: lucene-net-user@incubator.apache.org
>>> Subject: Multi-valued fields
>>>
>>> Hi all.
>>>
>>> There's a way to create a multi-valued field in Lucene.net? Something
>>> like?
>>>
>>> Field f = new Field("categories", "", Field.Store.YES,
>>> Field.Index.ANALYZED);
>>> f.AddValue("baby")
>>> f.AddValue("black cat")
>>> f.AddValue("brown horse")
>>>
>>> Thank's
>>>
>>> "Então aproximaram-se os que estavam no barco, e adoraram-no, dizendo: És
>>> verdadeiramente o Filho de Deus." (Mateus 14:33)
>>>
>

Re: Multi-valued fields

Posted by Michael Garski <mg...@myspace-inc.com>.
I've not done it, but I believe you can just add another field with  
the same name. The process of appending the second value for the field  
happens internally. Check the javadocs for 2.4 under the Document.Add  
method where the field is added to the document to confirm.

Michael

On Nov 7, 2009, at 3:37 AM, André Maldonado  
<an...@gmail.com> wrote:

> Hi Nitin. Understood, but how I do it?
>
> What method I have to use to add multiple values?
>
> Thank's
>
> "Então aproximaram-se os que estavam no barco, e adoraram-no, dizend 
> o: És
> verdadeiramente o Filho de Deus." (Mateus 14:33)
>
>
> On Sat, Nov 7, 2009 at 03:13, Nitin Shiralkar  
> <ni...@coreobjects.com>wrote:
>
>> Yes, you can add multiple values using same field name and all the  
>> values
>> would get indexed. So your searches would work fine. However since  
>> you are
>> storing the field, you need to remember that Lucene will only  
>> return last
>> value indexed under that field. If you intend to retrieve all  
>> values, then
>> you can consider adding a dummy field with all values concatenated  
>> together.
>>
>>
>> -----Original Message-----
>> From: André Maldonado [mailto:andre.maldonado@gmail.com]
>> Sent: Saturday, November 07, 2009 12:55 AM
>> To: lucene-net-user@incubator.apache.org
>> Subject: Multi-valued fields
>>
>> Hi all.
>>
>> There's a way to create a multi-valued field in Lucene.net?  
>> Something like?
>>
>> Field f = new Field("categories", "", Field.Store.YES,
>> Field.Index.ANALYZED);
>> f.AddValue("baby")
>> f.AddValue("black cat")
>> f.AddValue("brown horse")
>>
>> Thank's
>>
>> "Então aproximaram-se os que estavam no barco, e adoraram-no, dize 
>> ndo: És
>> verdadeiramente o Filho de Deus." (Mateus 14:33)
>>

Re: Multi-valued fields

Posted by André Maldonado <an...@gmail.com>.
Hi Nitin. Understood, but how I do it?

What method I have to use to add multiple values?

Thank's

"Então aproximaram-se os que estavam no barco, e adoraram-no, dizendo: És
verdadeiramente o Filho de Deus." (Mateus 14:33)


On Sat, Nov 7, 2009 at 03:13, Nitin Shiralkar <ni...@coreobjects.com>wrote:

> Yes, you can add multiple values using same field name and all the values
> would get indexed. So your searches would work fine. However since you are
> storing the field, you need to remember that Lucene will only return last
> value indexed under that field. If you intend to retrieve all values, then
> you can consider adding a dummy field with all values concatenated together.
>
>
> -----Original Message-----
> From: André Maldonado [mailto:andre.maldonado@gmail.com]
> Sent: Saturday, November 07, 2009 12:55 AM
> To: lucene-net-user@incubator.apache.org
> Subject: Multi-valued fields
>
> Hi all.
>
> There's a way to create a multi-valued field in Lucene.net? Something like?
>
> Field f = new Field("categories", "", Field.Store.YES,
> Field.Index.ANALYZED);
> f.AddValue("baby")
> f.AddValue("black cat")
> f.AddValue("brown horse")
>
> Thank's
>
> "Então aproximaram-se os que estavam no barco, e adoraram-no, dizendo: És
> verdadeiramente o Filho de Deus." (Mateus 14:33)
>

RE: Multi-valued fields

Posted by Nitin Shiralkar <ni...@coreobjects.com>.
Yes, you can add multiple values using same field name and all the values would get indexed. So your searches would work fine. However since you are storing the field, you need to remember that Lucene will only return last value indexed under that field. If you intend to retrieve all values, then you can consider adding a dummy field with all values concatenated together.


-----Original Message-----
From: André Maldonado [mailto:andre.maldonado@gmail.com]
Sent: Saturday, November 07, 2009 12:55 AM
To: lucene-net-user@incubator.apache.org
Subject: Multi-valued fields

Hi all.

There's a way to create a multi-valued field in Lucene.net? Something like?

Field f = new Field("categories", "", Field.Store.YES,
Field.Index.ANALYZED);
f.AddValue("baby")
f.AddValue("black cat")
f.AddValue("brown horse")

Thank's

"Então aproximaram-se os que estavam no barco, e adoraram-no, dizendo: És
verdadeiramente o Filho de Deus." (Mateus 14:33)