2012-08-28 154 views
0

索尔支持嵌套文档吗?有没有更好的方法来实现这种文件?索引索引嵌套文档

<doc> 
    <field name="name">Mr. Test</field> 
    <field name="case"> 
     <field name="link">http://foo.com</field> 
     <field name="date">1-2-1234</filed> 
     <field name="title">My title</filed> 
    </field> 
    <field name="case"> 
     <field name="link">http://foo.com/2/</field> 
     <field name="date">1-2-1234</filed> 
     <field name="title">My title 2</filed> 
    </field> 
</doc> 

我有一个人是多个案件的一部分。这种模式的形式是否与solr合法?不同的人也可以是同一案件的一部分。所以它看起来像一个关系数据库的任务,但是我使用solr来处理这个项目。

回答

1

较新版本的Solr提供支持嵌套文档

指数此JSON

[ 
    { 
    "id": "1", 
    "title": "Solr adds block join support", 
    "content_type": "parentDocument", 
    "_childDocuments_": [ 
     { 
     "id": "2", 
     "comments": "SolrCloud supports it too!" 
     } 
    ] 
    }, 
    { 
    "id": "3", 
    "title": "Lucene and Solr 4.5 is out", 
    "content_type": "parentDocument", 
    "_childDocuments_": [ 
     { 
     "id": "4", 
     "comments": "Lots of new features" 
     } 
    ] 
    } 
] 

进入schema.xml中,u必须补充它们到达这里使用的是“标题”的所有字段, “CONTENT_TYPE”, “评论”。参数“childDocuments”是solr注意的一个参数,它理解这是一个子文档和“content_type”:“parentDocument”是solr的标识符,以便了解这是父文档。如果我们查询

"*":"*" 

我们应该查看4个文档。现在我们可以在Block and join query parsers的帮助下获得父母或小孩的文件。试试这个查询

http://localhost:8983/solr/collection_test/select?q={!child%20of=%22content_type:parentDocument%22}title:lucene 

而这一次

http://localhost:8983/solr/collection_test/select?q={!parent%20which=%22content_type:parentDocument%22}comments:SolrCloud 
+0

。在你的JSON格式的一些错误。在“_childDocuments_”之后应该有一个“[”: –

+0

@Lijo:thnks ..我改变了它。 – Gunjan

+0

: - 如果我想索引像solr中的下面,我该怎么做? [{ “ID”: “1”, “COMPANY_ID”: “1”, “COMPANY_NAME”: “COMPANY_1”, “meta_categories”:[ { “CAT_ID”: “1”, “cat_name” : “时尚” }, { “CAT_ID”: “2”, “cat_name”: “体育” } ], “main_categories”:[ { “cat_name”: “1”, “ cat_name“:”fashion“ }, { ”cat_name“:”2“, ”cat_name“:”sports“ } ] –