0

In my current lucene index I want to be able to find documents by their isocountry code so I store this as an indexed field, but I also want to to find documents that do not have a country code so when building the index I store an '-' in the field for that record if they have no country code.

This applies to other fields as well, and it means that as well as increasing the size of my index there are indexing problems if the '-' is valid real data for the field.

Is there a better way of doing this in the latest versions of lucene ?

Paul Taylor
  • 13,411
  • 42
  • 184
  • 351
  • 1
    did you try a negated range query that catches all possible values for that field ? NOT foo:[* TO *] – omu_negru Jun 23 '14 at 09:40
  • @omu_negru seems very hacky ? – Paul Taylor Jun 23 '14 at 12:12
  • 1
    as far as i know it's the only way to get what you're looking for. Of course, a more elegant way would be to have a default value (NA or -1 for positive ints...etc) that would be added to the field in case no previous value is found. That would require some code on your part – omu_negru Jun 23 '14 at 12:16
  • @omu_negru that is what Im currently doing, but I thought I might not need to anymore – Paul Taylor Jun 23 '14 at 12:47
  • omu_negru is correct - you could do it in query time as negate range query (which is expensive) or in index time, as you do by adding some NULL value – Mysterion Jun 24 '14 at 07:51
  • @Mysterion when you say NULL you dont actually mean NULL do you, i.e I cant store nulls, is there not some kind of defacto value to use as NULL – Paul Taylor Jun 27 '14 at 06:55
  • BTW not really a duplicate as I'm asking about uses LuceneCore and the answer referred to only talks about LuceneSolr – Paul Taylor Jun 27 '14 at 06:56

0 Answers0