From hibernate-commits at lists.jboss.org Wed Dec 3 15:10:04 2008 Content-Type: multipart/mixed; boundary="===============7472537210297299958==" MIME-Version: 1.0 From: hibernate-commits at lists.jboss.org To: hibernate-commits at lists.jboss.org Subject: [hibernate-commits] Hibernate SVN: r15657 - search/trunk/doc/reference/en/modules. Date: Wed, 03 Dec 2008 15:10:03 -0500 Message-ID: --===============7472537210297299958== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: hardy.ferentschik Date: 2008-12-03 15:10:03 -0500 (Wed, 03 Dec 2008) New Revision: 15657 Modified: search/trunk/doc/reference/en/modules/mapping.xml Log: doc update Modified: search/trunk/doc/reference/en/modules/mapping.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- search/trunk/doc/reference/en/modules/mapping.xml 2008-12-03 16:41:15 U= TC (rev 15656) +++ search/trunk/doc/reference/en/modules/mapping.xml 2008-12-03 20:10:03 U= TC (rev 15657) @@ -48,11 +48,16 @@ entities not annotated with @Indexed will be igno= red by the indexing process): = - @Entity + + Making a class indexable using the + <classname>@Indexed</classname> annotation + + @Entity @Indexed(index=3D"indexes/essays") public class Essay { ... } + = The index attribute tells Hibernate what the Lucene directory name is (usually a directory on your file system). = It @@ -189,7 +194,11 @@ can omit @DocumentId. The chosen entity id will also be used as docu= ment id. = - @Entity + + Adding <classname>@DocumentId</classname> ad + <classname>@Field</classname> annotations to an indexed entity</ti= tle> + + <programlisting>@Entity @Indexed(index=3D"indexes/essays") public class Essay { ... @@ -205,6 +214,7 @@ <emphasis role=3D"bold">@Field(index=3DIndex.TOKENIZED)</emphasis> public String getText() { return text; } }</programlisting> + </example> = <para>The above annotations define an index with three fields: <literal>id</literal> , <literal>Abstract</literal> and @@ -222,7 +232,10 @@ index it twice - once tokenized and once untokenized. @Fields allows= to achieve this goal.</para> = - <programlisting>@Entity + <example> + <title>Using @Fields to map a property multiple times + + @Entity @Indexed(index =3D "Book" ) public class Book { @Fields( { @@ -235,6 +248,7 @@ = ... } + = The field summary is indexed twice, once as summary in a tokenized way, and once as @@ -267,7 +281,10 @@ (In the Lucene query parser language, it would translate into address.city:Atlanta). = - @Entity + + Using @IndexedEmbedded to index associations + + @Entity @Indexed public class Place { @Id @@ -301,6 +318,7 @@ private Set<Place> places; ... } + = In this example, the place fields will be indexed in the Place index. The Place index @@ -325,7 +343,11 @@ = Let's make our example a bit more complex: = - @Entity + + Nested usage of <classname>@IndexedEmbedded</classname> and + <classname>@ContainedIn</classname> + + @Entity @Indexed public class Place { @Id @@ -369,6 +391,7 @@ private String name; ... } + = Any @*ToMany, @*ToOne and @Embedded attribute can be annotated with @@ -464,7 +487,11 @@ can override the object type targeted by Hibernate Search using the targetElement parameter. = - @Entity + + Using the <literal>targetElement</literal> property of + <classname>@IndexedEmbedded</classname> + + @Entity @Indexed public class Address { @Id @@ -485,6 +512,7 @@ = @Embeddable public class Owner implements Person { ... } + =
@@ -495,7 +523,11 @@ during the indexation process. You can use @Boost= at the @Field, method or class level. = - @Entity + + Using different ways of increasing the weight of an indexed + element using a boost factor + + @Entity @Indexed(index=3D"indexes/essays") @Boost(1.7f) public class Essay { @@ -506,7 +538,7 @@ public Long getId() { return id; } = @Field(name=3D"Abstract", index=3DIndex.TOKENIZED, store=3DStore.YES, = boost=3D@Boost(2f)) + role=3D"bold">@Boost(2f)) @Boost(1.5f) public String getSummary() { return summary; } = @@ -518,6 +550,7 @@ public String getISBN() { return isbn; } = } + = In our example, Essay's probability to reach the top of the search list will be multiplied by 1.7. The @@ -545,7 +578,10 @@ even per @Field (useful when multiple fields are indexed from a sing= le property). = - @Entity + + Different ways of specifying an analyzer + + @Entity @Indexed @Analyzer(impl =3D EntityAnalyzer.class) public class MyEntity { @@ -566,6 +602,7 @@ = ... } + = In this example, EntityAnalyzer is used= to index all tokenized properties (eg. name), except @@ -627,7 +664,11 @@ distribution of Hibernate Search provides these dependecies in its lib directory. = - @AnalyzerDef(name=3D"customanalyzer", + + <classname>@AnalyzerDef</classname> and the Solr + framework + + @AnalyzerDef(name=3D"customanalyzer", tokenizer =3D @TokenizerDef(factory =3D StandardTokenizerFactory.c= lass), filters =3D { @TokenFilterDef(factory =3D ISOLatin1AccentFilterFactory.c= lass), @@ -640,6 +681,7 @@ public class Team { ... } + = A tokenizer is defined by its factory which is responsible f= or building the tokenizer and using the optional list of parameters. = This @@ -660,7 +702,10 @@ @Analyzer declaration using the definition = name rather than declaring an implementation class. = - @Entity + + Referencing an analyzer by name + + @Entity @Indexed @AnalyzerDef(name=3D"customanalyzer", ... ) public class Team { @@ -678,6 +723,7 @@ @Field @Analyzer(definition =3D "customanalyze= r") private String description; } + = Analyzer instances declared by @AnalyzerDef are available by their name in= the @@ -1093,7 +1139,11 @@ interface. All implementations have to be thread-safe as they are = used concurrently. = - /** + + Implementing your own + <classname>StringBridge</classname> + + /** * Padding Integer bridge. * All numbers will be padded with 0 to match 5 digits * @@ -1114,6 +1164,7 @@ return paddedInteger.append( rawInteger ).toString(); } } + = Then any property or field can use this bridge thanks to the @FieldBridge annotation @@ -1127,9 +1178,12 @@ parameters are passed through the @FieldBridge annotation. = - public class PaddedIntegerBridge implements String= Bridge, ParameterizedBridge { + + Passing parameters to your bridge implementation = + public class PaddedIntegerBridge implements Stri= ngBridge, ParameterizedBridge { + public static String PADDING_PROPERTY =3D "padding"; private int padding =3D 5; //default = @@ -1156,6 +1210,7 @@ params =3D @Parameter(name=3D"padding= ", value=3D"10") ) private Integer length; + = The ParameterizedBridge interface can= be implemented by StringBridge , @@ -1174,8 +1229,12 @@ the object out of it. There is not difference in the way the @FieldBridge annotation is used. = - public class PaddedIntegerBridge implements TwoWay= StringBridge, ParameterizedBridge { + + Implementing a TwoWayStringBridge which can for example be + used for id properties = + public class PaddedIntegerBridge implements TwoW= ayStringBridge, ParameterizedBridge { + public static String PADDING_PROPERTY =3D "padding"; private int padding =3D 5; //default = @@ -1207,6 +1266,7 @@ params =3D @Parameter(name=3D"padding", value=3D"10") = private Integer id; + = It is critically important for the two-way process to be idempotent (ie object =3D stringToObject( objectToString( object )= ) @@ -1227,7 +1287,11 @@ You can for example store a given property in two different document fields: = - /** + + Implementing the FieldBridge interface in order to a given + property into multiple document fields + + /** * Store the date in 3 different fields - year, month, day - to ease Range= Query per * year, month or day (eg get all the elements of December for the last 5 = years). * = @@ -1271,6 +1335,7 @@ //property @FieldBridge(impl =3D DateSplitBridge.class) private Date date; +
=
@@ -1287,7 +1352,10 @@ termVector attribute discussed in section . = - @Entity + + Implementing a class bridge + + @Entity @Indexed @ClassBridge(name=3D"branchnetwork", index=3DIndex.TOKENIZED, @@ -1331,6 +1399,7 @@ document.add( field ); } } + = In this example, the particular CatFieldsClassBridge is applied to the @@ -1366,13 +1435,17 @@ sure however, to not use this annotation with @DocumentId as your system will break. = - @ProvidedId (bridge =3D org.my.own.package.MyCustomB= ridge) + + Providing your own id + + @ProvidedId (bridge =3D org.my.own.package.MyCusto= mBridge) @Indexed public class MyClass{ @Field String MyString; ... } +
--===============7472537210297299958==--