: Subject: Re: Is it possible to search for the empty string?
: 
: Not out of the box.
: 
: Fields are parsed into tokens and queries search on tokens. An empty 
: string has no tokens for that field and a missing field has no tokens 
: for that field.

that's a missleading over simplification of what *normally* happens.

it is absolutely possible to have documents with fields whose indexed 
temrs consist of the empty string, and to search for those empty 
strings -- the most trivial way being with a simple StrField -- but using 
TExtField with some creative analyzers it's also very possible..


$ curl 
'http://localhost:8983/solr/techproducts/select?q=*:*&facet=true&facet.field=foo_s&wt=json&indent=true&omitHeader=true'
{
  "response":{"numFound":3,"start":0,"docs":[
      {
        "id":"foo_blank",
        "foo_s":"",
        "_version_":1501816569733316608},
      {
        "id":"foo_non_blank",
        "foo_s":"bar",
        "_version_":1501816583564034048},
      {
        "id":"foo_missing",
        "_version_":1501816591383265280}]
  },
  "facet_counts":{
    "facet_queries":{},
    "facet_fields":{
      "foo_s":[
        "",1,
        "bar",1]},
    "facet_dates":{},
    "facet_ranges":{},
    "facet_intervals":{},
    "facet_heatmaps":{}}}

$ curl 
'http://localhost:8983/solr/techproducts/select?q=foo_s:""&wt=json&indent=true&omitHeader=true'
{
  "response":{"numFound":1,"start":0,"docs":[
      {
        "id":"foo_blank",
        "foo_s":"",
        "_version_":1501816569733316608}]
  }}

$ curl 
'http://localhost:8983/solr/techproducts/select?q=foo_s:*&wt=json&indent=true&omitHeader=true'
{
  "response":{"numFound":2,"start":0,"docs":[
      {
        "id":"foo_blank",
        "foo_s":"",
        "_version_":1501816569733316608},
      {
        "id":"foo_non_blank",
        "foo_s":"bar",
        "_version_":1501816583564034048}]
  }}

$ curl 
'http://localhost:8983/solr/techproducts/select?q=-foo_s:*&wt=json&indent=true&omitHeader=true'
{
  "response":{"numFound":1,"start":0,"docs":[
      {
        "id":"foo_missing",
        "_version_":1501816591383265280}]
  }}


-Hoss
http://www.lucidworks.com/

Reply via email to