Last updated by maurice 3 years ago
constant
Summary
A class mapping option that defines constant searchable data for every instance of the class or hierarchy.Syntax
constant name: "the_name", value: "a value"
constant name: "the_name", value: "a value", option: value, option: value
constant name: "the_name", values: ["a value", 3, "another value"]
constant name: "the_name", values: ["a value", 3, "another value"], option: value, option: value
Description
Allows you define constant searchable values for every instance of a class or heirarchy, as if you had a class property which had the same value for every instance.You can define any number ofconstant@s within the @searchable @Closure@.Each constant requires a name and value or values@, allowing you to associate a single or multiple values with a key. The @value and values keywords are interchangeable; use whichever is better for you.This allows you search based on this constant value with a prefix query, eg, "my_constant:foo" would match if a class had defined a constant with name "my_constant" and whose value is or whose values contains @"foo"@.Because constants are a bit like fixed-value searchable properties they share similar mapping options to searchable properties.Parameters
Options
- @analyzer@ - The name of a configured analyzer used to analyze this constant. 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 constant; with a negative value, demotes search results that hit this constant. Default is @1.0@
- @excludeFromAll@ - Whether the constant should be excluded from the generated
"all"searchable text field in the index. One of"yes"@, @"no"or @"no_analyzed"@ - @index@ - How or if the constant is made into searchable text. One of
"'no"@, @"not_analyzed"or @"analyzed"@. - @spellCheck@ - Should the values of the constant 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"@. Setting to @"no"does not store the constant in the index and still makes it searchable (depending on theindexoption). This is best if you do not need to access it from the index itself, eg, with Lucene/Compass."compress"is useful for large or binary property values. Default is @"yes"@ - @termVector@ - Should the term-vector data be collected for the constant? 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.
- @converter@ - The name of a configured Converter used to convert the constant value(s) to searchable text
Examples
static searchable = { constant name: "type", value: "media", boost: 1.5 constant name: "capacity", values: [60, 90, 180] }
static searchable = { mapping { constant name: "type", value: "media", boost: 1.5 constant name: "capacity", values: [60, 90, 180] } }



