Skip to content
Browse files

Added the Keyword type to Elastic::Model::Types to use for not_analyz…

…ed text fields
  • Loading branch information...
1 parent bd6cc75 commit be34ae6e58525d12a82cf6cb3a193851ac86b102 @clintongormley committed Aug 1, 2012
View
1 lib/Elastic/Manual/Attributes.pod
@@ -178,6 +178,7 @@ C<no>: This attribute will not be indexed, and will thus not be searchable.
C<not_analyzed>: This attribute will be indexed using exactly the value
that you pass in, eg C<FoO> will be stored (and searchable) as C<FoO>.
+Also see L<Elastic::Model::TypeMap::ES/Keyword>.
=item *
View
26 lib/Elastic/Model/TypeMap/ES.pm
@@ -47,6 +47,16 @@ has_type 'Elastic::Model::Types::UID',
};
#===================================
+has_type 'Elastic::Model::Types::Keyword',
+#===================================
+ map_via {
+ type => 'string',
+ index => 'not_analyzed',
+ omit_norms => 1,
+ omit_term_freq_and_positions => 1,
+ };
+
+#===================================
has_type 'Elastic::Model::Types::GeoPoint',
#===================================
deflate_via {
@@ -98,6 +108,22 @@ for ElasticSearch specific types.
=head1 TYPES
+=head2 Elastic::Model::Types::Keyword
+
+Attributes of type L<Elastic::Model::Types/Keyword> are in/deflated
+via L<Elastic::Model::TypeMap::Moose/Any> and are mapped as:
+
+ {
+ type => 'string',
+ index => 'not_analyzed',
+ omit_norms => 1,
+ omit_term_freq_and_positions => 1,
+ }
+
+It is a suitable type to use for string attributes which should not
+be analyzed, and will not be used for scoring. Rather they are suitable
+to use as filters.
+
=head2 Elastic::Model::Types::UID
An L<Elastic::Model::UID> is deflated into a hash ref and reinflated
View
18 lib/Elastic/Model/Types.pm
@@ -22,6 +22,7 @@ use MooseX::Types -declare => [ qw(
HighlightArgs
IndexMapping
IndexNames
+ Keyword
Latitude
Longitude
MultiField
@@ -189,6 +190,10 @@ subtype Timestamp, as Num;
#===================================
#===================================
+subtype Keyword, as Str;
+#===================================
+
+#===================================
class_type UID, { class => 'Elastic::Model::UID' };
#===================================
coerce UID, from Str, via { Elastic::Model::UID->new_from_string($_) };
@@ -217,6 +222,19 @@ use and some which will be useful generally.
=head1 PUBLIC TYPES
+=head2 Keyword
+
+ use Elastic::Model::Types qw(Keyword);
+
+ has 'status' => (
+ is => 'ro',
+ isa => Keyword
+ );
+
+C<Keyword> is a sub-type of C<Str>. It is provided to make it easy to map
+string values which should not be analyzed (eg a C<status> field rather than
+a C<comment_body> field). See L<Elastic::Model::TypeMap::ES/Keyword>.
+
=head2 Binary
use Elastic::Model::Types qw(Binary);
View
6 t/10_typemaps/06_map_es.t
@@ -6,6 +6,12 @@ use warnings;
our $test_class = 'TypeTest::ES';
our @mapping = (
+ 'keyword' => {
+ type => 'string',
+ index => 'not_analyzed',
+ omit_norms => 1,
+ omit_term_freq_and_positions => 1,
+ },
'binary' => { type => 'binary' },
'geopoint' => { type => 'geo_point' },
'timestamp' => { type => 'date' },
View
9 t/10_typemaps/16_flate_es.t
@@ -28,6 +28,15 @@ note '';
my ( $de, $in );
+## KEYWORD ##
+
+{
+ ( $de, $in ) = flators('keyword');
+
+ is $de->('foo'), 'foo', 'Deflate: keyword';
+ is $in->('bar'), 'bar', 'Inflate: keyword';
+}
+
## BINARY ##
{
View
9 t/lib/TypeTest/ES.pm
@@ -1,11 +1,18 @@
package TypeTest::ES;
use Elastic::Doc;
-use Elastic::Model::Types qw(GeoPoint Binary Timestamp);
+use Elastic::Model::Types qw(Keyword GeoPoint Binary Timestamp);
# UID and Timestamp tested in Objects
#===================================
+has 'keyword_attr' => (
+#===================================
+ is => 'ro',
+ isa => Keyword,
+);
+
+#===================================
has 'geopoint_attr' => (
#===================================
is => 'ro',

0 comments on commit be34ae6

Please sign in to comment.
Something went wrong with that request. Please try again.