can we add duplicated field in Lucene?

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

can we add duplicated field in Lucene?

David-317
Hi all:
can we add duplicate field in Lucene like the following:

doc.add(new Field("author", "author1", Field.Store.YES,
Field.Index.UN_TOKENIZED));
doc.add(new Field("author", "author2", Field.Store.YES,
Field.Index.UN_TOKENIZED));

How will Lucene act?

if I want add two authors to the index , how can I do?   except concat the
authors' string, because maybe I should support Range search  for datetime.

Appreciate your help!


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

Re: can we add duplicated field in Lucene?

Erik Hatcher

On Jan 9, 2007, at 10:24 PM, David wrote:
> Hi all:
> can we add duplicate field in Lucene like the following:

Yup, no problem!

>
> doc.add(new Field("author", "author1", Field.Store.YES,
> Field.Index.UN_TOKENIZED));
> doc.add(new Field("author", "author2", Field.Store.YES,
> Field.Index.UN_TOKENIZED));
>
> How will Lucene act?

It'll be as if you did concatenate them yourself into a single field,  
with a slight caveat.  Multiple same-named fields can have a virtual  
positional gap added to them (see the setPositionGap feature).  This  
can prevent phrases searching across instances of the field.  For  
example, if you indexed "Samual Clemens" and "Mark Twain" as two  
separate "author" fields, but left the default position gap setting,  
someone could query for "clemons twain" and get a hit as an exact  
phrase match.

> if I want add two authors to the index , how can I do?   except  
> concat the
> authors' string, because maybe I should support Range search  for  
> datetime.

You'd do it just the way you're doing.

        Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]