使用Solr在複雜JSON中搜索的好設計是什麼?比如有可能是一個文件,如:用於在複雜JSON中搜索的Solr設計
{
"books" : [
{
"title" : "Some title",
"author" : "Some author",
"genres" : [
"thriller",
"drama"
]
},
{
"title" : "Some other title",
"author" : "Some author",
"genres" : [
"comedy",
"nonfiction",
"thriller"
]
}
]
}
一個示例查詢,將得到的是有一本書,其作者是「一些作家」等書的類型之一是「劇」的所有文檔。
現在我想出的設計是具有在schema.xml中一個dynamicField該指標一切爲文本(現在),像這樣:
<dynamicField name="*" type="text" index="true" stored="true"/>
然後SolrJ用來解析JSON併爲每個數據段創建一個SolrInputDocument字段。例如,這些都將用於例如創建現場/值JSON以上:
books0.title : "Some title"
books0.author : "Some author"
books0.genres0 : "thriller"
books0.genres1 : "drama"
books1.title : "Some other title"
books1.author : "Some author"
books1.genres0 : "comedy"
books1.genres1 : "nonfiction"
books1.genres2 : "thriller"
在這一點上,我們可以使用LukeRequestHandler把所有的字段索引,然後做出一個大的Solr查詢檢查我們感興趣的所有字段。對於上面的示例查詢,查詢將檢查所有「books#.author」和「books#.genres#」字段。這個解決方案看起來不夠優雅,如果有很多字段,查詢可能會變得非常大。
能夠在字段名中使用通配符會很有用,但我認爲Solr並不可行。
有沒有更好的方法來實現這一點,可能是通過在模式中使用一些巧妙的「copyField」和「multiValued」組合?
你的意思是每個「書」都是一個文件嗎? – Thomas 2012-07-17 14:26:14
是一個單獨的文件。 – Jayendra 2012-07-17 14:31:44
我接受了這個答案,因爲它讓我感到這個http://www.lucidimagination.com/search/document/93e8b09e90b0076c/help_with_denormalizing_issues#60890dcb99a3004d,它讓我確信,JSON中的每個「對象」都需要被編入索引爲自己的文檔。 – Thomas 2012-07-18 13:45:04