From 87efccf677d8fc7ddbe7f600ddbdc3b0495aec14 Mon Sep 17 00:00:00 2001 From: kimchy Date: Sat, 6 Nov 2010 01:04:14 +0200 Subject: [PATCH] expose boolean and Object as values for TermQueryBuilder and FieldQueryBuilder --- .../query/xcontent/FieldQueryBuilder.java | 14 ++++- .../index/query/xcontent/QueryBuilders.java | 52 +++++++++++++++++-- .../query/xcontent/TermQueryBuilder.java | 12 ++++- 3 files changed, 72 insertions(+), 6 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FieldQueryBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FieldQueryBuilder.java index 175d1833be1..616ca357cb8 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FieldQueryBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FieldQueryBuilder.java @@ -129,7 +129,19 @@ public class FieldQueryBuilder extends BaseQueryBuilder { * @param name The name of the field * @param query The query string */ - private FieldQueryBuilder(String name, Object query) { + public FieldQueryBuilder(String name, boolean query) { + this(name, (Object) query); + } + + /** + * A query that executes the query string against a field. It is a simplified + * version of {@link QueryStringQueryBuilder} that simply runs against + * a single field. + * + * @param name The name of the field + * @param query The query string + */ + public FieldQueryBuilder(String name, Object query) { this.name = name; this.query = query; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/QueryBuilders.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/QueryBuilders.java index c698e34fbc9..e5ddf25b264 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/QueryBuilders.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/QueryBuilders.java @@ -83,13 +83,13 @@ public abstract class QueryBuilders { } /** - * A Query that matches documents using fuzzy query. + * A Query that matches documents containing a term. * * @param name The name of the field * @param value The value of the term */ - public static FuzzyQueryBuilder fuzzyQuery(String name, String value) { - return new FuzzyQueryBuilder(name, value); + public static TermQueryBuilder termQuery(String name, double value) { + return new TermQueryBuilder(name, value); } /** @@ -98,10 +98,30 @@ public abstract class QueryBuilders { * @param name The name of the field * @param value The value of the term */ - public static TermQueryBuilder termQuery(String name, double value) { + public static TermQueryBuilder termQuery(String name, boolean value) { return new TermQueryBuilder(name, value); } + /** + * A Query that matches documents containing a term. + * + * @param name The name of the field + * @param value The value of the term + */ + public static TermQueryBuilder termQuery(String name, Object value) { + return new TermQueryBuilder(name, value); + } + + /** + * A Query that matches documents using fuzzy query. + * + * @param name The name of the field + * @param value The value of the term + */ + public static FuzzyQueryBuilder fuzzyQuery(String name, String value) { + return new FuzzyQueryBuilder(name, value); + } + /** * A query that executes the query string against a field. It is a simplified * version of {@link QueryStringQueryBuilder} that simply runs against @@ -161,6 +181,30 @@ public abstract class QueryBuilders { return new FieldQueryBuilder(name, query); } + /** + * A query that executes the query string against a field. It is a simplified + * version of {@link QueryStringQueryBuilder} that simply runs against + * a single field. + * + * @param name The name of the field + * @param query The query string + */ + public static FieldQueryBuilder fieldQuery(String name, boolean query) { + return new FieldQueryBuilder(name, query); + } + + /** + * A query that executes the query string against a field. It is a simplified + * version of {@link QueryStringQueryBuilder} that simply runs against + * a single field. + * + * @param name The name of the field + * @param query The query string + */ + public static FieldQueryBuilder fieldQuery(String name, Object query) { + return new FieldQueryBuilder(name, query); + } + /** * A Query that matches documents containing terms with a specified prefix. * diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/TermQueryBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/TermQueryBuilder.java index 628f68012e5..2a6db1da95d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/TermQueryBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/TermQueryBuilder.java @@ -92,7 +92,17 @@ public class TermQueryBuilder extends BaseQueryBuilder { * @param name The name of the field * @param value The value of the term */ - private TermQueryBuilder(String name, Object value) { + public TermQueryBuilder(String name, boolean value) { + this(name, (Object) value); + } + + /** + * Constructs a new term query. + * + * @param name The name of the field + * @param value The value of the term + */ + public TermQueryBuilder(String name, Object value) { this.name = name; this.value = value; }