Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solr query syntax for array field

How do I search within an array field?

I am using solr 4.2 with default settings. I indexed a few html and pdf documents using SolrNet. Here is a sample result for such a document when I search using the admin search *:*

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>

The search using content:* returns 0 results.

like image 402
chadisbad Avatar asked Apr 03 '13 17:04

chadisbad


1 Answers

Instead of content:* try with content:[* TO *]. That will fetch all documents that have the field content non-empty.

For querying arrays/multi-valued fields, it depends on what you want to do. If you have a multi-valued field like:

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

and you want to find documents having both death and history as tag_names then issue a query like

q=tag_names:(death AND history)

To do an OR, use

q=tag_names:(death OR history)
like image 71
arun Avatar answered Sep 21 '22 01:09

arun