Last updated by maurice 5 years ago

Searchable Property

Summary

Used to map searchable properties.

Syntax

static searchable = {
    propertyName options
}

Description

Maps the class's propertyName property with the given options.

Supports regular properties (those you declare the field for) and synthetic properties (those with no class field but a "getter" method).

It is possible to map the same property with multiple different mappings (as long as the mappings are semantically valid), see the examples.

Parameters

Options

  • @accessor@ - How the property is accessed. One of "field" or @"property"@. Default is @"property"@
  • @analyzer@ - The name of a configured analyzer used to analyze this property. Default is "default" which is a built-in analyzer (Lucene's StandardAnalyzer)
  • @boost@ - A decimal boost value. With a positive value, promotes search results for hits in this property; with a negative value, demotes search results that hit this property. Default is @1.0@
  • @excludeFromAll@ - Whether the property should be excluded from the generated "all" searchable text field in the index. One of "yes"@, @"no" or @"no_analyzed"@
  • @format@ - How the property is formatted when made into searchable text. Applies to objects like @Date@s and @Number@s usually for the purposes of range searches. Value is a format string for the appropriate formatter.
  • @index@ - How or if the property is made into searchable text. One of "'no"@, @"not_analyzed" or @"analyzed"@.
  • @name@ - The name of the field in the search index. Can be used with multiple mappings for the same property, each with their own name. Default is propertyName@. This becomes the name of the field in the index, so if @name is @"title"@, you can target that field with a query like @"title:grails"@
  • @nullValue@ - The value to use if the property is null when indexed.
  • @propertyConverter@ - The name of a configured ResourcePropertyConverter which converts the property from/to searchable text.
  • @reverse@ - Whether the property should be reversed when made searchable. One of "no"@, @"reader" or @"string@". Default is @"no"@
  • @spellCheck@ - Should the values of the property be included in the spell-check index? Either "include" or @"exclude"@. If not defined then inherits the class's own spell-check mapping.
  • @store@ - Should the value be stored in the index? One of "yes"@, @"no" or "compress"@. If @"no" then the property may still be searchable (depending on the index option), but when re-creating the object for search results this property will always be null. "compress" is useful for large or binary property values. Default is @"yes"@
  • @termVector@ - Should the term-vector data be collected for the property in the index? One of @"yes"@, @"no"@, @"with_positions@", @"with_offsets@", @"with_positions_offsets@". If not defined inherits the class's term-vector mapping. This is required for more-like-this searches.

Examples

// Give matches in the title field a boost
title boost: 2.0

// Format a date property
// so it's easy to search with range queries
createdAt format: "yyyyMMdd"

// Format a number property padding with zeroes
// so it's easy to search with range queries
numVotes format: "0000"

// Multiple mappings for the same class property, one analyzed the other not
// This means we can search for, say, "tagsExact:Miami" and it would only match the
// exact text "Miami", not "MiAmi" or "miami" etc.
// And we can search for "tags:Miami" and match any variation 
tags index: 'not_analyzed', name: 'tagsExact'
tags index: 'analyzed'