Author: navssurtani
Date: 2009-11-13 10:59:46 -0500 (Fri, 13 Nov 2009)
New Revision: 17973
Added:
search/trunk/src/main/java/org/hibernate/search/query/dsl/
search/trunk/src/main/java/org/hibernate/search/query/dsl/QueryContext.java
search/trunk/src/main/java/org/hibernate/search/query/dsl/SealedQueryBuilder.java
search/trunk/src/test/java/org/hibernate/search/test/query/dsl/
search/trunk/src/test/java/org/hibernate/search/test/query/dsl/QueryContextTest.java
Modified:
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/ProvidedIdPerson.java
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/ProvidedIdTest.java
Log:
Basic steps starting to be taken wrt the dsl.
Added: search/trunk/src/main/java/org/hibernate/search/query/dsl/QueryContext.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/query/dsl/QueryContext.java
(rev 0)
+++ search/trunk/src/main/java/org/hibernate/search/query/dsl/QueryContext.java 2009-11-13
15:59:46 UTC (rev 17973)
@@ -0,0 +1,52 @@
+package org.hibernate.search.query.dsl;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Query;
+
+/**
+ * Class that will be called by the {@link
org.hibernate.search.query.dsl.SealedQueryBuilder} each time someone wants
+ * to create a new query instance.
+ *
+ * @author Navin Surtani
+ */
+
+
+public class QueryContext {
+
+ private Analyzer analyzer;
+ private String field;
+ private String search;
+
+ public QueryContext search(String mySearch){
+ this.search = mySearch;
+ return this;
+ }
+
+ public QueryContext onField(String onField){
+ this.field = onField;
+ return this;
+ }
+
+ public QueryContext withAnalyzer(Analyzer analyzer){
+ this.analyzer = analyzer;
+ return this;
+ }
+
+ public Query build() throws ParseException {
+ QueryParser parser;
+
+ if (analyzer != null){
+ parser = new QueryParser(field, analyzer);
+ }
+ else{
+ // Do we just use a StandardAnalyzer?
+ parser = new QueryParser(field, new StandardAnalyzer());
+ }
+
+ return parser.parse(search);
+ }
+
+}
Added: search/trunk/src/main/java/org/hibernate/search/query/dsl/SealedQueryBuilder.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/query/dsl/SealedQueryBuilder.java
(rev 0)
+++
search/trunk/src/main/java/org/hibernate/search/query/dsl/SealedQueryBuilder.java 2009-11-13
15:59:46 UTC (rev 17973)
@@ -0,0 +1,19 @@
+package org.hibernate.search.query.dsl;
+
+/**
+ * // TODO: Document this
+ *
+ * @author Navin Surtani
+ */
+
+
+public class SealedQueryBuilder {
+
+ public SealedQueryBuilder(){
+
+ }
+
+ public QueryContext getContext(){
+ return new QueryContext();
+ }
+}
Modified:
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/ProvidedIdPerson.java
===================================================================
---
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/ProvidedIdPerson.java 2009-11-13
15:03:29 UTC (rev 17972)
+++
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/ProvidedIdPerson.java 2009-11-13
15:59:46 UTC (rev 17973)
@@ -24,24 +24,25 @@
*/
package org.hibernate.search.test.id.providedId;
-import org.hibernate.search.annotations.*;
-import org.hibernate.search.bridge.builtin.LongBridge;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.ProvidedId;
+import org.hibernate.search.annotations.Store;
import javax.persistence.Entity;
-import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import java.io.Serializable;
/**
- * @author Navin Surtani (<a
href="mailto:nsurtani@redhat.com">nsurtani@redhat.com</a>)
+ * @author Navin Surtani
*/
@Entity
-@ProvidedId(bridge = @FieldBridge(impl = LongBridge.class))
+@ProvidedId
@Indexed
public class ProvidedIdPerson implements Serializable {
- @Id
@GeneratedValue
private long id;
Modified:
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/ProvidedIdTest.java
===================================================================
---
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/ProvidedIdTest.java 2009-11-13
15:03:29 UTC (rev 17972)
+++
search/trunk/src/test/java/org/hibernate/search/test/id/providedId/ProvidedIdTest.java 2009-11-13
15:59:46 UTC (rev 17973)
@@ -38,7 +38,7 @@
import org.hibernate.search.test.SearchTestCase;
/**
- * @author Navin Surtani (<a
href="mailto:nsurtani@redhat.com">nsurtani@redhat.com</a>)
+ * @author Navin Surtani
*/
public class ProvidedIdTest extends SearchTestCase {
Added:
search/trunk/src/test/java/org/hibernate/search/test/query/dsl/QueryContextTest.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/query/dsl/QueryContextTest.java
(rev 0)
+++
search/trunk/src/test/java/org/hibernate/search/test/query/dsl/QueryContextTest.java 2009-11-13
15:59:46 UTC (rev 17973)
@@ -0,0 +1,30 @@
+package org.hibernate.search.test.query.dsl;
+
+import org.hibernate.search.query.dsl.QueryContext;
+import org.hibernate.search.test.SearchTestCase;
+import org.hibernate.search.test.query.Person;
+
+/**
+ * Test Class for {@link org.hibernate.search.query.dsl.QueryContext}
+ *
+ * @author Navin Surtani
+ */
+
+
+public class QueryContextTest extends SearchTestCase {
+
+ protected Class<?>[] getMappings() {
+ Class[] clazz = new Class[1];
+ clazz[0] = Person.class;
+ return clazz;
+ }
+
+ public void testSameInstance(){
+ QueryContext qc = new QueryContext();
+
+ QueryContext qc2 = qc.search("findStuff");
+
+ assert qc.equals(qc2);
+ }
+
+}
Show replies by date