[hibernate-commits] Hibernate SVN: r19632 - in search/trunk/hibernate-search/src: main/java/org/hibernate/search/query/dsl/v2/impl and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Fri May 28 19:42:48 EDT 2010


Author: epbernard
Date: 2010-05-28 19:42:47 -0400 (Fri, 28 May 2010)
New Revision: 19632

Modified:
   search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/QueryBuilder.java
   search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/TermContext.java
   search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/ConnectedFuzzyContext.java
   search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/ConnectedQueryBuilder.java
   search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/ConnectedTermContext.java
   search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/ConnectedWildcardContext.java
   search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/dsl/DSLTest.java
Log:
HSEARCH-507 Query DSL Rename exact() to keyword() and put fuzzy() and wildcard() as options

Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/QueryBuilder.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/QueryBuilder.java	2010-05-28 23:41:39 UTC (rev 19631)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/QueryBuilder.java	2010-05-28 23:42:47 UTC (rev 19632)
@@ -9,21 +9,17 @@
 	/**
 	 * build a term query
 	 */
-	TermContext exact();
+	TermContext keyword();
 
 	/**
-	 * Use a fuzzy search approximation (aka edit distance)
+	 * find matching elements within a range
 	 */
-	FuzzyContext fuzzy();
+	RangeContext range();
 
 	/**
-	 * Treat the query as a wildcard:
-	 *  - ? represents any single character
-	 *  - * represents any character sequence
-	 * For faster results, it is recommended that the query text does not
-	 * start with ? or *
+	 * find an sentence (words can be inversed according to the slop factor
 	 */
-	WildcardContext wildcard();
+	PhraseContext phrase();
 
 	/**
 	 * Boolean query
@@ -31,16 +27,6 @@
 	BooleanJunction<BooleanJunction> bool();
 
 	/**
-	 * find matching elements within a range
-	 */
-	RangeContext range();
-
-	/**
-	 * find an sentence (words can be inversed according to the slop factor
-	 */
-	PhraseContext phrase();
-
-	/**
 	 * Query matching all documents
 	 * Typically mixed with a boolean query.
 	 */

Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/TermContext.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/TermContext.java	2010-05-28 23:41:39 UTC (rev 19631)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/TermContext.java	2010-05-28 23:42:47 UTC (rev 19632)
@@ -13,4 +13,17 @@
 
 	TermMatchingContext onFields(String... field);
 
+	/**
+	 * Use a fuzzy search approximation (aka edit distance)
+	 */
+	FuzzyContext fuzzy();
+
+	/**
+	 * Treat the query as a wildcard:
+	 *  - ? represents any single character
+	 *  - * represents any character sequence
+	 * For faster results, it is recommended that the query text does not
+	 * start with ? or *
+	 */
+	WildcardContext wildcard();
 }

Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/ConnectedFuzzyContext.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/ConnectedFuzzyContext.java	2010-05-28 23:41:39 UTC (rev 19631)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/ConnectedFuzzyContext.java	2010-05-28 23:42:47 UTC (rev 19632)
@@ -16,10 +16,10 @@
 	private final QueryCustomizer queryCustomizer;
 	private final TermQueryContext context;
 
-	public ConnectedFuzzyContext(Analyzer queryAnalyzer, SearchFactory factory) {
+	public ConnectedFuzzyContext(Analyzer queryAnalyzer, SearchFactory factory, QueryCustomizer queryCustomizer) {
 		this.factory = factory;
 		this.queryAnalyzer = queryAnalyzer;
-		this.queryCustomizer = new QueryCustomizer();
+		this.queryCustomizer = queryCustomizer;
 		this.context = new TermQueryContext( TermQueryContext.Approximation.FUZZY);
 	}
 

Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/ConnectedQueryBuilder.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/ConnectedQueryBuilder.java	2010-05-28 23:41:39 UTC (rev 19631)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/ConnectedQueryBuilder.java	2010-05-28 23:42:47 UTC (rev 19632)
@@ -26,18 +26,10 @@
 		this.factory = factory;
 	}
 
-	public TermContext exact() {
+	public TermContext keyword() {
 		return new ConnectedTermContext(queryAnalyzer, factory);
 	}
 
-	public FuzzyContext fuzzy() {
-		return new ConnectedFuzzyContext(queryAnalyzer, factory);
-	}
-
-	public WildcardContext wildcard() {
-		return new ConnectedWildcardContext(queryAnalyzer, factory);
-	}
-
 	public RangeContext range() {
 		return new ConnectedRangeContext( queryAnalyzer, factory );
 	}

Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/ConnectedTermContext.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/ConnectedTermContext.java	2010-05-28 23:41:39 UTC (rev 19631)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/ConnectedTermContext.java	2010-05-28 23:42:47 UTC (rev 19632)
@@ -4,8 +4,10 @@
 import org.apache.lucene.search.Filter;
 
 import org.hibernate.search.SearchFactory;
+import org.hibernate.search.query.dsl.v2.FuzzyContext;
 import org.hibernate.search.query.dsl.v2.TermContext;
 import org.hibernate.search.query.dsl.v2.TermMatchingContext;
+import org.hibernate.search.query.dsl.v2.WildcardContext;
 
 /**
  * @author Emmanuel Bernard
@@ -31,17 +33,25 @@
 		return new ConnectedTermMatchingContext(context, fields, queryCustomizer, queryAnalyzer, factory);
 	}
 
-	public TermContext boostedTo(float boost) {
+	public FuzzyContext fuzzy() {
+		return new ConnectedFuzzyContext( queryAnalyzer, factory, queryCustomizer );
+	}
+
+	public WildcardContext wildcard() {
+		return new ConnectedWildcardContext( queryAnalyzer, factory, queryCustomizer);
+	}
+
+	public ConnectedTermContext boostedTo(float boost) {
 		queryCustomizer.boostedTo( boost );
 		return this;
 	}
 
-	public TermContext constantScore() {
+	public ConnectedTermContext constantScore() {
 		queryCustomizer.constantScore();
 		return this;
 	}
 
-	public TermContext filter(Filter filter) {
+	public ConnectedTermContext filter(Filter filter) {
 		queryCustomizer.filter(filter);
 		return this;
 	}

Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/ConnectedWildcardContext.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/ConnectedWildcardContext.java	2010-05-28 23:41:39 UTC (rev 19631)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/query/dsl/v2/impl/ConnectedWildcardContext.java	2010-05-28 23:42:47 UTC (rev 19632)
@@ -16,10 +16,10 @@
 	private final QueryCustomizer queryCustomizer;
 	private final TermQueryContext context;
 
-	public ConnectedWildcardContext(Analyzer queryAnalyzer, SearchFactory factory) {
+	public ConnectedWildcardContext(Analyzer queryAnalyzer, SearchFactory factory, QueryCustomizer queryCustomizer) {
 		this.factory = factory;
 		this.queryAnalyzer = queryAnalyzer;
-		this.queryCustomizer = new QueryCustomizer();
+		this.queryCustomizer = queryCustomizer;
 		this.context = new TermQueryContext( TermQueryContext.Approximation.WILDCARD);
 	}
 

Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/dsl/DSLTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/dsl/DSLTest.java	2010-05-28 23:41:39 UTC (rev 19631)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/dsl/DSLTest.java	2010-05-28 23:42:47 UTC (rev 19632)
@@ -1,6 +1,5 @@
 package org.hibernate.search.test.query.dsl;
 
-import java.text.Format;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
@@ -40,32 +39,30 @@
 				.buildQueryBuilder().forEntity( Month.class ).get();
 		Query
 		//regular term query
-		query = monthQb.exact().onField( "mythology" ).matching( "cold" ).createQuery();
+		query = monthQb.keyword().onField( "mythology" ).matching( "cold" ).createQuery();
 
 		assertEquals( 0, fts.createFullTextQuery( query, Month.class ).getResultSize() );
 
 		//term query based on several words
-		query = monthQb.exact().onField( "mythology" ).matching( "colder darker" ).createQuery();
+		query = monthQb.keyword().onField( "mythology" ).matching( "colder darker" ).createQuery();
 
 		assertEquals( 1, fts.createFullTextQuery( query, Month.class ).getResultSize() );
 
 		//term query applying the analyzer and generating one term per word
-		query = monthQb.exact().onField( "mythology_stem" ).matching( "snowboard" ).createQuery();
+		query = monthQb.keyword().onField( "mythology_stem" ).matching( "snowboard" ).createQuery();
 
 		assertEquals( 1, fts.createFullTextQuery( query, Month.class ).getResultSize() );
 
 		//term query applying the analyzer and generating several terms per word
-		query = monthQb.exact().onField( "mythology_ngram" ).matching( "snobored" ).createQuery();
+		query = monthQb.keyword().onField( "mythology_ngram" ).matching( "snobored" ).createQuery();
 
 		assertEquals( 1, fts.createFullTextQuery( query, Month.class ).getResultSize() );
 
 		//term query not using analyzers
-		query = monthQb.exact().onField( "mythology" ).ignoreAnalyzer().matching( "Month" ).createQuery();
+		query = monthQb.keyword().onField( "mythology" ).ignoreAnalyzer().matching( "Month" ).createQuery();
 
 		assertEquals( 0, fts.createFullTextQuery( query, Month.class ).getResultSize() );
 
-		query = monthQb.exact().onField( "mythology" ).matching( "Month" ).createQuery();
-
 		transaction.commit();
 
 		cleanData( fts );
@@ -81,9 +78,10 @@
 
 		//fuzzy search with custom threshold and prefix
 		query = monthQb
-				.fuzzy()
-					.threshold( .8f )
-					.prefixLength( 1 )
+				.keyword()
+					.fuzzy()
+						.threshold( .8f )
+						.prefixLength( 1 )
 					.onField( "mythology" )
 						.matching( "calder" )
 						.createQuery();
@@ -92,7 +90,8 @@
 
 		//wildcard query
 		query = monthQb
-				.wildcard()
+				.keyword()
+					.wildcard()
 					.onField( "mythology" )
 						.matching( "mon*" )
 						.createQuery();
@@ -115,8 +114,8 @@
 		//combined query, January and february both contain whitening but February in a longer text
 		query = monthQb
 				.bool()
-					.should( monthQb.exact().onField( "mythology" ).matching( "whitening" ).createQuery() )
-					.should( monthQb.exact().onField( "history" ).matching( "whitening" ).createQuery() )
+					.should( monthQb.keyword().onField( "mythology" ).matching( "whitening" ).createQuery() )
+					.should( monthQb.keyword().onField( "history" ).matching( "whitening" ).createQuery() )
 				.createQuery();
 
 		List<Month> results = fts.createFullTextQuery( query, Month.class ).list();
@@ -127,8 +126,8 @@
 		//since history is boosted, February should come first though
 		query = monthQb
 				.bool()
-					.should( monthQb.exact().onField( "mythology" ).matching( "whitening" ).createQuery() )
-					.should( monthQb.exact().onField( "history" ).boostedTo( 30 ).matching( "whitening" ).createQuery() )
+					.should( monthQb.keyword().onField( "mythology" ).matching( "whitening" ).createQuery() )
+					.should( monthQb.keyword().onField( "history" ).boostedTo( 30 ).matching( "whitening" ).createQuery() )
 				.createQuery();
 
 		results = fts.createFullTextQuery( query, Month.class ).list();
@@ -151,7 +150,7 @@
 		Query
 
 		//combined query, January and february both contain whitening but February in a longer text
-		query = monthQb.exact()
+		query = monthQb.keyword()
 						.onField( "mythology" )
 						.andField( "history" )
 						.matching( "whitening" ).createQuery();
@@ -161,7 +160,7 @@
 		assertEquals( "January", results.get( 0 ).getName() );
 
 		//combined query, January and february both contain whitening but February in a longer text
-		query = monthQb.exact()
+		query = monthQb.keyword()
 						.onFields( "mythology", "history" )
 							.boostedTo( 30 )
 						.matching( "whitening" ).createQuery();
@@ -172,7 +171,7 @@
 
 		//boosted query, January and february both contain whitening but February in a longer text
 		//since history is boosted, February should come first though
-		query = monthQb.exact()
+		query = monthQb.keyword()
 							.onField( "mythology" )
 							.andField( "history" )
 								.boostedTo( 30 )
@@ -199,7 +198,7 @@
 		//must
 		query = monthQb
 				.bool()
-					.must( monthQb.exact().onField( "mythology" ).matching( "colder" ).createQuery() )
+					.must( monthQb.keyword().onField( "mythology" ).matching( "colder" ).createQuery() )
 					.createQuery();
 
 		List<Month> results = fts.createFullTextQuery( query, Month.class ).list();
@@ -210,7 +209,7 @@
 		query = monthQb
 				.bool()
 					.should( monthQb.all().createQuery() )
-					.must( monthQb.exact().onField( "mythology" ).matching( "colder" ).createQuery() )
+					.must( monthQb.keyword().onField( "mythology" ).matching( "colder" ).createQuery() )
 						.not()
 					.createQuery();
 		results = fts.createFullTextQuery( query, Month.class ).list();
@@ -220,7 +219,7 @@
 		//implicit must not + all (not recommended)
 		query = monthQb
 				.bool()
-					.must( monthQb.exact().onField( "mythology" ).matching( "colder" ).createQuery() )
+					.must( monthQb.keyword().onField( "mythology" ).matching( "colder" ).createQuery() )
 						.not()
 					.createQuery();
 		results = fts.createFullTextQuery( query, Month.class ).list();
@@ -230,7 +229,7 @@
 		//all except (recommended)
 		query = monthQb
 				.all()
-					.except( monthQb.exact().onField( "mythology" ).matching( "colder" ).createQuery() )
+					.except( monthQb.keyword().onField( "mythology" ).matching( "colder" ).createQuery() )
 					.createQuery();
 
 		results = fts.createFullTextQuery( query, Month.class ).list();



More information about the hibernate-commits mailing list