2013-04-03 90 views
9

如何在數組字段中搜索?數組字段的Solr查詢語法

我正在使用默認設置的solr 4.2。 我使用SolrNet索引了一些html和pdf文檔。下面是當我搜索使用管理搜索*:*

enter code here 
<doc> 
<str name="id">2</str> 
<date name="last_modified">2011-12-19T17:33:25Z</date> 
<str name="author">name</str> 
<str name="author_s">name</str> 
<arr name="title"> 
    <str>CALIFORNIA CODES</str> 
</arr> 
<arr name="content_type"> 
    <str>application/pdf</str> 
</arr> 
<str name="resourcename">T01041.pdf</str> 
<arr name="content"> 
    <str> PDF text here </str> 
</arr> 
<long name="_version_">1431314431195742208</long> 
</doc> 

使用content:*返回0的結果的搜索這樣的文件的樣本結果。

回答

9

而不是content:*嘗試content:[* TO *]。這將獲取非空的字段content的所有文檔。

對於查詢數組/多值字段,這取決於你想要做什麼。如果你有一個像多值字段:

<arr name="tag_names"> 
    <str>death</str> 
    <str>history</str> 
    <str>people</str> 
    <str>historical figures</str> 
    <str>assassinations</str> 
</arr> 

,你想找到同時具有deathhistorytag_names文件然後發出像

q=tag_names:(death AND history) 

查詢做一個OR,使用

q=tag_names:(death OR history) 
+0

'內容:[* TO * ]'不起作用 – chadisbad

+0

你可以發佈fieldType及其對'content'字段的定義嗎?如果它不是一個索引字段,那麼你就無法搜索它。 – arun

+0

我把它發佈在我的答案中。你是對的,那是問題所在。謝謝。 – chadisbad

-1

text:*工程。它會返回我的所有文檔。

我得到這個從架構:

 <!-- Main body of document extracted by SolrCell. 
     NOTE: This field is not indexed by default, since it is also copied to "text" 
     using copyField below. This is to save space. Use this field for returning and 
     highlighting document content. Use the "text" field to search the content. --> 
    <field name="content" type="text_general" indexed="false" stored="true" multiValued="true"/> 


    <!-- catchall field, containing all other searchable text fields (implemented 
     via copyField further on in this schema --> 
    <field name="text" type="text_general" indexed="true" stored="false" multiValued="true"/> 
1

回答你的問題很簡單。

Schema.xml的文件說,該場名=「內容」收錄=「假」即內容字段是不可搜索。因此,如果您搜索「內容」的任何內容,它將返回0結果。

請更改您的schema.xml文件並將內容字段設置爲indexed =「true」,以便它可以使字段可控。

保存文件
重新啓動Solr。
清除索引。
重新編制文件

現在,你就可以做搜索上內容:*

請接受的答案,如果它解決您的問題...