You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Ananth V <an...@gmail.com> on 2012/06/08 10:18:33 UTC

Nested indexing doubt.

Hey guys,
               I'm trying to index nested documents in lucene 3.6. I have
the parent document having a 'type' and 'typename' fields and the children
having 'value' and 'author' fields. The below snippet is what i've written
to index them as a block. Is this correct? Is there any working piece of
code i can use. Googling wasn't helpful.

private static void addDoc(IndexWriter w,String type, String
typename,String value, String author, String value2, String author2) throws
IOException {
    ArrayList<Document> docs=new ArrayList<Document>();
    Document doc = new Document();
    doc.add(new Field("type", type, Field.Store.YES, Field.Index.ANALYZED));
    doc.add(new Field("typename", typename, Field.Store.YES,
Field.Index.ANALYZED));
    docs.add(doc);
    Document doc1 = new Document();
    doc1.add(new Field("value", value, Field.Store.YES,
Field.Index.ANALYZED));
    doc1.add(new Field("author", author, Field.Store.YES,
Field.Index.ANALYZED));
    docs.add(doc1);
    Document doc2 = new Document();
    doc2.add(new Field("value", value2, Field.Store.YES,
Field.Index.ANALYZED));
    doc2.add(new Field("author", author2, Field.Store.YES,
Field.Index.ANALYZED));
    docs.add(doc2);
    w.addDocuments(docs);
  }

Thanks,
Ananth.

Re: Nested indexing doubt.

Posted by Christoph Kaser <lu...@iconparc.de>.
Hi Ananth,

You have to add the child documents before the parent document, 
otherwise the blockjoinquery won't work.

Regards,
Christoph

Am 08.06.2012 10:18, schrieb Ananth V:
> Hey guys,
>                 I'm trying to index nested documents in lucene 3.6. I have
> the parent document having a 'type' and 'typename' fields and the children
> having 'value' and 'author' fields. The below snippet is what i've written
> to index them as a block. Is this correct? Is there any working piece of
> code i can use. Googling wasn't helpful.
>
> private static void addDoc(IndexWriter w,String type, String
> typename,String value, String author, String value2, String author2) throws
> IOException {
>      ArrayList<Document> docs=new ArrayList<Document>();
>      Document doc = new Document();
>      doc.add(new Field("type", type, Field.Store.YES, Field.Index.ANALYZED));
>      doc.add(new Field("typename", typename, Field.Store.YES,
> Field.Index.ANALYZED));
>      docs.add(doc);
>      Document doc1 = new Document();
>      doc1.add(new Field("value", value, Field.Store.YES,
> Field.Index.ANALYZED));
>      doc1.add(new Field("author", author, Field.Store.YES,
> Field.Index.ANALYZED));
>      docs.add(doc1);
>      Document doc2 = new Document();
>      doc2.add(new Field("value", value2, Field.Store.YES,
> Field.Index.ANALYZED));
>      doc2.add(new Field("author", author2, Field.Store.YES,
> Field.Index.ANALYZED));
>      docs.add(doc2);
>      w.addDocuments(docs);
>    }
>
> Thanks,
> Ananth.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org