can Lucene index different amount of attributes to one document?

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

can Lucene index different amount of attributes to one document?

David-317
Hi all:
    I know that we can use doc.add(attr, value) to add attributes to the
document, can we add different amount of attributes to one document?
for example, can this pseudo code  runnable?

public static Document Document(MyObject o)
{
    Document doc = new Document();

    for(i=0; i<o.attribute_len(); i++)
       if(o.attributes(i).value != "") //only if the attribute exist, we
index it.
              doc.add(new Field(o.attrbute(i).name, o.attrbute(i).value)
....);
    }
    return doc;
}

if we can do this, are there any special steps when search the on these
attributes?

Appreciate your help!



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

Re: can Lucene index different amount of attributes to one document?

Otis Gospodnetic-2
Yes, documents can have different fields.  One document can have fields A and B, and another document can have fields C and D.

Otis

----- Original Message ----
From: David <[hidden email]>
To: [hidden email]
Sent: Tuesday, January 9, 2007 5:55:28 AM
Subject: can Lucene index different amount of attributes to one document?

Hi all:
    I know that we can use doc.add(attr, value) to add attributes to the
document, can we add different amount of attributes to one document?
for example, can this pseudo code  runnable?

public static Document Document(MyObject o)
{
    Document doc = new Document();

    for(i=0; i<o.attribute_len(); i++)
       if(o.attributes(i).value != "") //only if the attribute exist, we
index it.
              doc.add(new Field(o.attrbute(i).name, o.attrbute(i).value)
....);
    }
    return doc;
}

if we can do this, are there any special steps when search the on these
attributes?

Appreciate your help!



--
David




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

Reply | Threaded
Open this post in threaded view
|

Re: can Lucene index different amount of attributes to one document?

Erick Erickson
But do be aware that, as one should expect, you can get a null result from
doc.get("a") if field "a" isn't in the document. You can use
doc.getFieldsto test ahead of the fetch if you need to.

Erick

On 1/9/07, Otis Gospodnetic <[hidden email]> wrote:

>
> Yes, documents can have different fields.  One document can have fields A
> and B, and another document can have fields C and D.
>
> Otis
>
> ----- Original Message ----
> From: David <[hidden email]>
> To: [hidden email]
> Sent: Tuesday, January 9, 2007 5:55:28 AM
> Subject: can Lucene index different amount of attributes to one document?
>
> Hi all:
>     I know that we can use doc.add(attr, value) to add attributes to the
> document, can we add different amount of attributes to one document?
> for example, can this pseudo code  runnable?
>
> public static Document Document(MyObject o)
> {
>     Document doc = new Document();
>
>     for(i=0; i<o.attribute_len(); i++)
>        if(o.attributes(i).value != "") //only if the attribute exist, we
> index it.
>               doc.add(new Field(o.attrbute(i).name, o.attrbute(i).value)
> ....);
>     }
>     return doc;
> }
>
> if we can do this, are there any special steps when search the on these
> attributes?
>
> Appreciate your help!
>
>
>
> --
> David
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>