简体   繁体   中英

grails searchable index null value

I'm trying to use searchable to find values by a null field. Or for that matter even index an id from a sub domain.

class Classified
{
    searchable = {
        only = ['id','title']
        id name: 'classified_id'
        title name: 'classified_title'
    }

    String title
    Dealer dealer
}

class Dealer
{
    String name
}

I want to just index the dealer_id that would exist in classifieds table to reference dealer. Then I want to be able to search classifieds by null dealer_id and numeric dealer_id. I tried making dealer searchable, but the problem with that is that if there is no dealer and classified.dealer_id is null it never even gets there.

  1. You can try Mapping the Dealer as component. So that dealer is contained within the Classified's index for easy searching.
  2. By default null values are not indexed and cannot be searched. So for the fields that you want to search for null values. Specifically tell searchable to index the null fields to other values (I use -1) and search for tht value.

Example,

static searchable = {
    dealer componenet true
}

And Within the Dealer

   static searchable = {
        property nullValue "-1"
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM