[hibernate-commits] Hibernate SVN: r14505 - in search/trunk: src/test/org/hibernate/search/test/query and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Fri Apr 11 12:56:02 EDT 2008


Author: epbernard
Date: 2008-04-11 12:56:02 -0400 (Fri, 11 Apr 2008)
New Revision: 14505

Modified:
   search/trunk/doc/reference/en/modules/mapping.xml
   search/trunk/src/test/org/hibernate/search/test/query/TermVectorTest.java
Log:
HSEARCH-141 doc (John Griffin)

Modified: search/trunk/doc/reference/en/modules/mapping.xml
===================================================================
--- search/trunk/doc/reference/en/modules/mapping.xml	2008-04-11 16:42:58 UTC (rev 14504)
+++ search/trunk/doc/reference/en/modules/mapping.xml	2008-04-11 16:56:02 UTC (rev 14505)
@@ -77,9 +77,9 @@
           <para>termVector: describes collections of term-frequency pairs. To
           utilize Term Vectors this attribute enables their being stored
           during indexing so they are stored with documents. The default value
-          is Field.TermVector.NO. </para>
+          is Field.TermVector.NO.</para>
 
-          <para>The different values of this attribute are </para>
+          <para>The different values of this attribute are</para>
 
           <informaltable align="left" width="">
             <tgroup cols="2">
@@ -97,7 +97,9 @@
                 <row>
                   <entry align="left">Field.TermVector.YES</entry>
 
-                  <entry>Store the term vectors of each document.</entry>
+                  <entry>Store the term vectors of each document. This
+                  produces two synchronized arrays, one contains document
+                  terms and the other contains the term's frequency.</entry>
                 </row>
 
                 <row>
@@ -109,15 +111,19 @@
                 <row>
                   <entry align="left">Field.TermVector.WITH_OFFSETS</entry>
 
-                  <entry>Store the term vector and token offset
-                  information</entry>
+                  <entry>Store the term vector and token offset information.
+                  This is the same as Field.TermVector.YES plus this contains
+                  the starting and ending offset position information for the
+                  terms</entry>
                 </row>
 
                 <row>
                   <entry align="left">Field.TermVector.WITH_POSITIONS</entry>
 
-                  <entry>Store the term vector and token position
-                  information</entry>
+                  <entry>Store the term vector and token position information.
+                  This is the same as Field.TermVector.YES plus this contains
+                  the ordinal positions of each occurrence of a term in a
+                  document.</entry>
                 </row>
 
                 <row>
@@ -125,7 +131,8 @@
                   align="left">Field.TermVector.WITH_POSITIONS_OFFSETS</entry>
 
                   <entry>Store the term vector, token position and offset
-                  information</entry>
+                  information. This is a combination of the YES, WITH_OFFSETS
+                  and WITH_POSITIONS.</entry>
                 </row>
               </tbody>
             </tgroup>
@@ -635,19 +642,17 @@
     <section>
       <title>Custom Bridge</title>
 
-      <para>Sometimes, the built-in bridges of Hibernate Search do not
-      cover some of your property types, or  the String representation
-      used by the bridge does not meet your requirements.
-      The following paragraphs describe several solutions
-      to this problem.</para>
+      <para>Sometimes, the built-in bridges of Hibernate Search do not cover
+      some of your property types, or the String representation used by the
+      bridge does not meet your requirements. The following paragraphs
+      describe several solutions to this problem.</para>
 
       <section>
         <title>StringBridge</title>
 
-        <para>The simpliest custom solution is to give Hibernate
-        Search an implementation of your expected
-        <emphasis>object to String</emphasis> bridge. To do so you need to
-        implements the
+        <para>The simpliest custom solution is to give Hibernate Search an
+        implementation of your expected <emphasis>object to String</emphasis>
+        bridge. To do so you need to implements the
         <literal>org.hibernate.search.bridge.StringBridge</literal>
         interface</para>
 
@@ -837,7 +842,8 @@
         custom field bridge implementation receives the entity instance as the
         value parameter instead of a particular property. Though not shown in
         this example, <classname>@ClassBridge</classname> supports the
-        <methodname>termVector</methodname> attribute discussed previously.</para>
+        <methodname>termVector</methodname> attribute discussed
+        previously.</para>
 
         <programlisting>@Entity
 @Indexed

Modified: search/trunk/src/test/org/hibernate/search/test/query/TermVectorTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/query/TermVectorTest.java	2008-04-11 16:42:58 UTC (rev 14504)
+++ search/trunk/src/test/org/hibernate/search/test/query/TermVectorTest.java	2008-04-11 16:56:02 UTC (rev 14505)
@@ -17,100 +17,92 @@
  * @author John Griffin
  */
 public class TermVectorTest extends SearchTestCase {
-	private static Log log = LogFactory.getLog( TermVectorTest.class );
+   private static Log log = LogFactory.getLog(TermVectorTest.class);
 
-	public void testPositionOffsets() throws Exception {
-		FullTextSession s = Search.createFullTextSession( openSession() );
-		createIndex( s );
+   public void testPositionOffsets() throws Exception {
+      FullTextSession s = Search.createFullTextSession(openSession());
+      createIndex(s);
 
-		s.clear();
-		Transaction tx = s.beginTransaction();
+      s.clear();
+      Transaction tx = s.beginTransaction();
 
-		// Here's how to get a reader from a FullTextSession
-		SearchFactory searchFactory = s.getSearchFactory();
-		DirectoryProvider provider = searchFactory.getDirectoryProviders( ElectricalProperties.class )[0];
-		ReaderProvider readerProvider = searchFactory.getReaderProvider();
-		IndexReader reader = readerProvider.openReader( provider );
+      // Here's how to get a reader from a FullTextSession
+      SearchFactory searchFactory = s.getSearchFactory();
+      DirectoryProvider provider = searchFactory.getDirectoryProviders(ElectricalProperties.class)[0];
+      ReaderProvider readerProvider = searchFactory.getReaderProvider();
+      IndexReader reader = readerProvider.openReader(provider);
 
-		/**
-		 * Since there are so many combinations of results here, rather
-		 * than try to do assertions, this test prints out all the results
-		 * found from the three ElectricalProperties entities. This will
-		 * do a better  job of demonstrating exactly what the result are. - J.G.
-		 */
-		///TODO: try and find some ways to assert it. Nobody reads the results. I've added 		
-		for (int x = 0; x < 3; x++) {
-			TermPositionVector vector = (TermPositionVector) reader.getTermFreqVector( x, "content" );
-			assertNotNull( vector );
-			String[] terms = vector.getTerms();
-			int[] freqs = vector.getTermFrequencies();
+      /**
+       * Since there are so many combinations of results here, we are only going
+       * to assert a few. - J.G.
+       */
+      int x = 0;
+      TermPositionVector vector = (TermPositionVector) reader.getTermFreqVector(x, "content");
+      assertNotNull(vector);
+      String[] terms = vector.getTerms();
+      int[] freqs = vector.getTermFrequencies();
 
-			for (int y = 0; y < vector.size(); y++) {
-				log.info( "doc# =>" + x );
-				log.info( " term => " + terms[y] );
-				log.info( " freq => " + freqs[y] );
+      assertEquals("electrical", terms[x]);
+      assertEquals(2, freqs[x]);
 
-				int[] positions = vector.getTermPositions( y );
-				TermVectorOffsetInfo[] offsets = vector.getOffsets( y );
-				for (int z = 0; z < positions.length; z++) {
-					log.info( " position => " + positions[z] );
-					log.info( " starting offset => " + offsets[z].getStartOffset() );
-					log.info( " ending offset => " + offsets[z].getEndOffset() );
-				}
-				log.info( "---------------" );
-			}
-		}
+      TermVectorOffsetInfo[] offsets = vector.getOffsets(x);
+      assertEquals(0, offsets[x].getStartOffset());
+      assertEquals(10, offsets[x].getEndOffset());
 
-		//cleanup
-		for (Object element : s.createQuery( "from " + ElectricalProperties.class.getName() ).list())
-			s.delete( element );
-		tx.commit();
-		s.close();
-	}
+      int[] termPositions = vector.getTermPositions(0);
+      assertEquals(0, termPositions[0]);
+      assertEquals(3, termPositions[1]);
 
-	public void testNoTermVector() throws Exception {
-		FullTextSession s = Search.createFullTextSession( openSession() );
-		Transaction tx = s.beginTransaction();
+      //cleanup
+      for (Object element : s.createQuery("from " + Employee.class.getName()).list()) s.delete(element);
+      tx.commit();
+      s.close();
+   }
 
-		Employee e1 = new Employee( 1000, "Griffin", "ITech" );
-		s.save( e1 );
-		tx.commit();
-		s.clear();
 
-		tx = s.beginTransaction();
+   public void testNoTermVector() throws Exception {
+      FullTextSession s = Search.createFullTextSession(openSession());
+      Transaction tx = s.beginTransaction();
 
-		// Here's how to get a reader from a FullTextSession
-		SearchFactory searchFactory = s.getSearchFactory();
-		DirectoryProvider provider = searchFactory.getDirectoryProviders( Employee.class )[0];
-		ReaderProvider readerProvider = searchFactory.getReaderProvider();
-		IndexReader reader = readerProvider.openReader( provider );
+      Employee e1 = new Employee(1000, "Griffin", "ITech");
+      s.save(e1);
+      tx.commit();
+      s.clear();
 
-		TermPositionVector vector = (TermPositionVector) reader.getTermFreqVector( 0, "dept" );
-		assertNull( "should not find a term position vector", vector );
+      tx = s.beginTransaction();
 
-		//cleanup
-		for (Object element : s.createQuery( "from " + ElectricalProperties.class.getName() ).list())
-			s.delete( element );
-		tx.commit();
-		s.close();
-	}
+      // Here's how to get a reader from a FullTextSession
+      SearchFactory searchFactory = s.getSearchFactory();
+      DirectoryProvider provider = searchFactory.getDirectoryProviders(Employee.class)[0];
+      ReaderProvider readerProvider = searchFactory.getReaderProvider();
+      IndexReader reader = readerProvider.openReader(provider);
 
-	private void createIndex(FullTextSession s) {
-		Transaction tx = s.beginTransaction();
-		ElectricalProperties e1 = new ElectricalProperties( 1000, "Electrical Engineers measure Electrical Properties" );
-		s.save( e1 );
-		ElectricalProperties e2 = new ElectricalProperties( 1001, "Electrical Properties are interesting" );
-		s.save( e2 );
-		ElectricalProperties e3 = new ElectricalProperties( 1002, "Electrical Properties are measurable properties" );
-		s.save( e3 );
+      TermPositionVector vector = (TermPositionVector) reader.getTermFreqVector(0, "dept");
+      assertNull("should not find a term position vector", vector);
 
-		tx.commit();
-	}
+      //cleanup
+      for (Object element : s.createQuery("from " + ElectricalProperties.class.getName()).list())
+         s.delete(element);
+      tx.commit();
+      s.close();
+   }
 
-	protected Class[] getMappings() {
-		return new Class[] {
-				ElectricalProperties.class,
-				Employee.class
-		};
-	}
+   private void createIndex(FullTextSession s) {
+      Transaction tx = s.beginTransaction();
+      ElectricalProperties e1 = new ElectricalProperties(1000, "Electrical Engineers measure Electrical Properties");
+      s.save(e1);
+      ElectricalProperties e2 = new ElectricalProperties(1001, "Electrical Properties are interesting");
+      s.save(e2);
+      ElectricalProperties e3 = new ElectricalProperties(1002, "Electrical Properties are measurable properties");
+      s.save(e3);
+
+      tx.commit();
+   }
+
+   protected Class[] getMappings() {
+      return new Class[]{
+         ElectricalProperties.class,
+         Employee.class
+      };
+   }
 }




More information about the hibernate-commits mailing list