Skip to content
Browse files

add boost to textquery

  • Loading branch information...
1 parent 5ac5ab1 commit e4dd143cec26077b34fba5f5485c8fd3decbcf29 @medcl committed Apr 10, 2012
View
BIN ElasticSearch.Client.suo
Binary file not shown.
View
2 ElasticSearch.Client/Domain/Document.cs
@@ -14,7 +14,7 @@ public class Document
var dict = new Dictionary<string, object>();
if (Hits != null)
{
- foreach (var fileItem in Hits.Fields)
+ foreach (var fileItem in Hits.Source)
{
if (dict.ContainsKey(fileItem.Key))
{
View
8 ElasticSearch.Client/Domain/Hits.cs
@@ -7,7 +7,11 @@ namespace ElasticSearch.Client.Domain
public class Hits
{
[JsonProperty("_source")]
- public Dictionary<string, object> Fields = new Dictionary<string, object>();
+ public Dictionary<string, object> Source = new Dictionary<string, object>();
+
+ [JsonProperty("fields")]
+ public Dictionary<string, object> Fields;
+
[JsonProperty("_id")]
public string Id;
[JsonProperty("_index")]
@@ -33,7 +37,7 @@ public override string ToString()
stringBuilder.Append(" _version:");
stringBuilder.Append(Version);
stringBuilder.Append(" _source:");
- foreach (var field in Fields)
+ foreach (var field in Source)
{
stringBuilder.Append(field.Key);
stringBuilder.Append(", ");
View
2 ElasticSearch.Client/Domain/SearchResult.cs
@@ -80,7 +80,7 @@ public int GetTotalCount()
foreach (Hits hit in hitStatus.Hits)
{
var dict = new Dictionary<string, object>();
- foreach (var fileItem in hit.Fields)
+ foreach (var fileItem in hit.Source)
{
if (dict.ContainsKey(fileItem.Key))
{
View
1 ElasticSearch.Client/ElasticSearch.Client.csproj
@@ -97,6 +97,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="QueryDSL\Converters\Filter\AndFilterConvert.cs" />
<Compile Include="QueryDSL\Converters\Filter\NumericRangeFilterConverter.cs" />
+ <Compile Include="QueryDSL\Converters\Misc\TermsFacetConverterer.cs" />
<Compile Include="QueryDSL\Filter\AndFilter.cs" />
<Compile Include="QueryDSL\Converters\Filter\BoolFilterConvert.cs" />
<Compile Include="QueryDSL\Filter\BoolFilter.cs" />
View
46 ElasticSearch.Client/QueryDSL/Converters/Misc/TermsFacetConverterer.cs
@@ -0,0 +1,46 @@
+using System;
+using Newtonsoft.Json;
+
+namespace ElasticSearch.Client.QueryDSL
+{
+ internal class TermsFacetConverterer : JsonConverter
+ {
+ public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
+ {
+ TermsFacet term = (TermsFacet)value;
+ if (term != null)
+ {
+ if (term.facetItems != null)
+ {
+ writer.WriteStartObject();
+ foreach (TermsFacet.TermsFacetItem termsFacetItem in term.facetItems)
+ {
+ writer.WritePropertyName(termsFacetItem.FacetName);
+ writer.WriteStartObject();
+ //1
+ writer.WritePropertyName("terms");
+ writer.WriteStartObject();
+ writer.WritePropertyName("field");
+ writer.WriteValue(termsFacetItem.Field);
+ writer.WritePropertyName("size");
+ writer.WriteValue(termsFacetItem.Size);
+ writer.WriteEndObject();
+ //1
+ writer.WriteEndObject();
+ }
+ writer.WriteEndObject();
+ }
+ }
+ }
+
+ public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override bool CanConvert(Type objectType)
+ {
+ return typeof(TermsFacet).IsAssignableFrom(objectType);
+ }
+ }
+}
View
12 ElasticSearch.Client/QueryDSL/Converters/Query/QueryStringConverter.cs
@@ -13,17 +13,21 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
{
var stringBuilder = new StringBuilder();
stringBuilder.Append("{query_string:{ ");
- stringBuilder.Append("\"default_field\":\"" + term.DefaultField + "\" ");
- stringBuilder.Append(",\"query\":\"" + term.Query + "\" ");
+ if (!string.IsNullOrEmpty(term.DefaultField)) { stringBuilder.Append("\"default_field\":\"" + term.DefaultField + "\", "); }
+ stringBuilder.Append("\"query\":\"" + term.Query + "\" ");
+ if (term.Fields != null && term.Fields.Count > 0)
+ {
+ stringBuilder.Append(",\"fields\":[\"" + string.Join("\",\"", term.Fields.ToArray()) + "\"] ");
+ }
stringBuilder.Append(",\"default_operator\":\"" + term.DefaultOperator + "\" ");
- stringBuilder.Append(",\"analyzer\":\"" + term.Analyzer + "\" ");
+ if (!string.IsNullOrEmpty(term.Analyzer)) { stringBuilder.Append(",\"analyzer\":\"" + term.Analyzer + "\" "); }
stringBuilder.Append("}}");
//TODO Íê³É¸ü¶à²ÎÊý+ ²ÎÊýÅжÏ
writer.WriteRawValue(stringBuilder.ToString());
}
-
+
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
View
6 ElasticSearch.Client/QueryDSL/Converters/Query/TextQueryConverter.cs
@@ -39,6 +39,12 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
writer.WriteValue(term.Fuzziness);
}
+ if (!Equals(term.Boost, default(float)))
+ {
+ writer.WritePropertyName("boost");
+ writer.WriteValue(term.Boost);
+ }
+
if (!Equals(term.PrefixLength, default(int)))
{
writer.WritePropertyName("prefix_length");
View
64 ElasticSearch.Client/QueryDSL/ElasticQuery.cs
@@ -37,7 +37,7 @@ public ElasticQuery(IQuery query, SortItem sortItem, int from, int size)
public IQuery Query;
- public Facets Facets;
+ public IFacet Facets;
public ElasticQuery SetQuery(IQuery query)
{
@@ -76,24 +76,58 @@ public void SetFacets()
{
}
-
- public ElasticQuery AddFields(string[] fields)
- {
- if (Fields == null) { Fields = new List<string>(); }
- Fields.AddRange(fields);
- return this;
+
+ public ElasticQuery SetFacets(IFacet facet)
+ {
+ Facets = facet;
+ return this;
}
+
+ public ElasticQuery AddFields(string[] fields)
+ {
+ if (Fields == null) { Fields = new List<string>(); }
+ Fields.AddRange(fields);
+ return this;
+ }
}
- public class Facets
- {
-// public Dictionary<string ,IQuery>
+ public interface IFacet
+ {
+
+ }
+
+ [JsonConverter(typeof(TermsFacetConverterer))]
+ public class TermsFacet : IFacet
+ {
+ internal List<TermsFacetItem> facetItems;
+ public TermsFacet(string facetName, string field, int size = 10)
+ {
+ facetItems = new List<TermsFacetItem>();
+ var item = new TermsFacetItem();
+ item.FacetName = facetName;
+ item.Field = field;
+ item.Size = size;
+ facetItems.Add(item);
+ }
+
+ public TermsFacet AddTermFacet(string facetName, string field, int size = 10)
+ {
+ var item = new TermsFacetItem();
+ item.FacetName = facetName;
+ item.Field = field;
+ item.Size = size;
+ facetItems.Add(item);
+ return this;
+ }
+
+ public class TermsFacetItem
+ {
+ public string Field;
+ public int Size;
+ public string FacetName { get; set; }
+ }
+ }
- public void AddFacet(string facertName,string filterClause)
- {
-
- }
- }
public class Filter
{
View
526 ElasticSearch.Client/QueryDSL/Query/QueryStringQuery.cs
@@ -5,268 +5,274 @@
namespace ElasticSearch.Client.QueryDSL
{
- public enum Operator
- {
- OR,
- AND
- }
+ public enum Operator
+ {
+ OR,
+ AND
+ }
- /// <summary>
- /// A query that uses a query parser in order to parse its content.
- /// </summary>
- [JsonObject("query_string")]
- [JsonConverter(typeof(QueryStringConverter))]
- public class QueryStringQuery : IQuery
- {
- #region Properties
-
- /// <summary>
- /// The actual query to be parsed.
- /// </summary>
- public string Query { get; private set; }
- /// <summary>
- /// The default field for query terms if no prefix field is specified. Defaults to the _all field.
- /// </summary>
- [JsonProperty("default_field")]
- public string DefaultField { get; private set; }
- /// <summary>
- /// The query_string query can also run against multiple fields. The idea of running the query_string query against multiple
- /// fields is by internally creating several queries for the same query string, each with default_field that match the fields provided.
- /// Since several queries are generated, combining them can be automatically done either using a dis_max query or a simple bool query.
- /// For example (the name is boosted by 5 using ^5 notation):
- /// </summary>
- public List<string> Fields { get; private set; }
- /// <summary>
- /// The default operator used if no explicit operator is specified. For example,
- /// with a default operator of OR, the query capital of Hungary is translated to capital OR of OR Hungary,
- /// and with default operator of AND, the same query is translated to capital AND of AND
- /// Hungary. The default value is OR.
- /// </summary>
- [JsonProperty("default_operator")]
- [JsonConverter(typeof(StringEnumConverter))]
- public Operator DefaultOperator { get; private set; }
- /// <summary>
- /// The analyzer name used to analyze the query string.
- /// </summary>
- public string Analyzer { get; private set; }
- /// <summary>
- /// When set, * or ? are allowed as the first character. Defaults to true.
- /// </summary>
- [JsonProperty("allow_leading_wildcard")]
- public bool AllowLeadingWildcard { get; private set; }
- /// <summary>
- /// Whether terms of wildcard, prefix, fuzzy, and range queries are to be automatically lower-cased or
- /// not (since they are not analyzed). Defaults to true.
- /// </summary>
- [JsonProperty("lowercase_expanded_terms")]
- public bool LowercaseExpendedTerms { get; private set; }
- /// <summary>
- /// Get wheter position increments are enabled in result queries. Defaults to true.
- /// </summary>
- [JsonProperty("enable_position_increments")]
- public bool EnablePositionIncrements { get; private set; }
- /// <summary>
- /// Get the prefix length for fuzzy queries. Default is 0.
- /// </summary>
- [JsonProperty("fuzzy_prefix_length")]
- public int FuzzyPrefixLength { get; private set; }
- /// <summary>
- /// Set the minimum similarity for fuzzy queries. Defaults to 0.5
- /// </summary>
- [JsonProperty("fuzzy_min_sim")]
- public double FuzzyMinimumSimilarity { get; private set; }
- /// <summary>
- /// Get the default slop for phrases. If zero, then exact phrase matches are required. Default value is 0.
- /// </summary>
- [JsonProperty("phrase_slop")]
- public double PhraseSlop { get; private set; }
- /// <summary>
- /// Get the boost value of the query. Defaults to 1.0.
- /// </summary>
- [JsonProperty("boost")]
- [DefaultValue(1.0)]
- public double Boost { get; private set; }
-
- /// <summary>
- /// Gets wheter the queries should be combined using dis_max (set it to true), or a bool query (set it to false). Defaults to true. (only used when using multiple fields)
- /// </summary>
- [JsonProperty("use_dis_max")]
- public bool UseDismax { get; private set; }
- /// <summary>
- /// When using dis_max, the disjunction max tie breaker. Defaults to 0. (only used when using multiple fields)
- /// </summary>
- [JsonProperty("tie_breaker")]
- public int TieBreaker { get; private set; }
+ /// <summary>
+ /// A query that uses a query parser in order to parse its content.
+ /// </summary>
+ [JsonObject("query_string")]
+ [JsonConverter(typeof(QueryStringConverter))]
+ public class QueryStringQuery : IQuery
+ {
+ #region Properties
- /// <summary>
- /// By default, wildcards terms in a query string are not analyzed. By setting this value to true, a best effort will be made to analyze those as well.
- /// </summary>
- [JsonProperty("analyze_wildcard")]
- public bool AnalyzeWildcard { get; set; }
+ /// <summary>
+ /// The actual query to be parsed.
+ /// </summary>
+ public string Query { get; private set; }
+ /// <summary>
+ /// The default field for query terms if no prefix field is specified. Defaults to the _all field.
+ /// </summary>
+ [JsonProperty("default_field")]
+ public string DefaultField { get; private set; }
+ /// <summary>
+ /// The query_string query can also run against multiple fields. The idea of running the query_string query against multiple
+ /// fields is by internally creating several queries for the same query string, each with default_field that match the fields provided.
+ /// Since several queries are generated, combining them can be automatically done either using a dis_max query or a simple bool query.
+ /// For example (the name is boosted by 5 using ^5 notation):
+ /// </summary>
+ public List<string> Fields { get; private set; }
+ /// <summary>
+ /// The default operator used if no explicit operator is specified. For example,
+ /// with a default operator of OR, the query capital of Hungary is translated to capital OR of OR Hungary,
+ /// and with default operator of AND, the same query is translated to capital AND of AND
+ /// Hungary. The default value is OR.
+ /// </summary>
+ [JsonProperty("default_operator")]
+ [JsonConverter(typeof(StringEnumConverter))]
+ public Operator DefaultOperator { get; private set; }
+ /// <summary>
+ /// The analyzer name used to analyze the query string.
+ /// </summary>
+ public string Analyzer { get; private set; }
+ /// <summary>
+ /// When set, * or ? are allowed as the first character. Defaults to true.
+ /// </summary>
+ [JsonProperty("allow_leading_wildcard")]
+ public bool AllowLeadingWildcard { get; private set; }
+ /// <summary>
+ /// Whether terms of wildcard, prefix, fuzzy, and range queries are to be automatically lower-cased or
+ /// not (since they are not analyzed). Defaults to true.
+ /// </summary>
+ [JsonProperty("lowercase_expanded_terms")]
+ public bool LowercaseExpendedTerms { get; private set; }
+ /// <summary>
+ /// Get wheter position increments are enabled in result queries. Defaults to true.
+ /// </summary>
+ [JsonProperty("enable_position_increments")]
+ public bool EnablePositionIncrements { get; private set; }
+ /// <summary>
+ /// Get the prefix length for fuzzy queries. Default is 0.
+ /// </summary>
+ [JsonProperty("fuzzy_prefix_length")]
+ public int FuzzyPrefixLength { get; private set; }
+ /// <summary>
+ /// Set the minimum similarity for fuzzy queries. Defaults to 0.5
+ /// </summary>
+ [JsonProperty("fuzzy_min_sim")]
+ public double FuzzyMinimumSimilarity { get; private set; }
+ /// <summary>
+ /// Get the default slop for phrases. If zero, then exact phrase matches are required. Default value is 0.
+ /// </summary>
+ [JsonProperty("phrase_slop")]
+ public double PhraseSlop { get; private set; }
+ /// <summary>
+ /// Get the boost value of the query. Defaults to 1.0.
+ /// </summary>
+ [JsonProperty("boost")]
+ [DefaultValue(1.0)]
+ public double Boost { get; private set; }
- /// <summary>
- /// Default to false.
- /// </summary>
- [JsonProperty("auto_generate_phrase_queries")]
- public bool AutoGeneratePhraseQueries { get; set; }
- #endregion
-
- public QueryStringQuery(string query)
- {
- this.Query = query;
- this.DefaultField = "_all";
- this.DefaultOperator = Operator.OR;
- this.AllowLeadingWildcard = true;
- this.LowercaseExpendedTerms = true;
- this.EnablePositionIncrements = true;
- this.FuzzyMinimumSimilarity = 0.5;
- this.Boost = 1.0;
- this.UseDismax = true;
- this.TieBreaker = 0;
- }
+ /// <summary>
+ /// Gets wheter the queries should be combined using dis_max (set it to true), or a bool query (set it to false). Defaults to true. (only used when using multiple fields)
+ /// </summary>
+ [JsonProperty("use_dis_max")]
+ public bool UseDismax { get; private set; }
+ /// <summary>
+ /// When using dis_max, the disjunction max tie breaker. Defaults to 0. (only used when using multiple fields)
+ /// </summary>
+ [JsonProperty("tie_breaker")]
+ public int TieBreaker { get; private set; }
- public QueryStringQuery(List<string> fields,string query)
- {
- Fields = fields;
- Query = query;
- }
-
- /// <summary>
- /// The default field for query terms if no prefix field is specified.
- /// </summary>
- /// <param name="field">Defaults to the _all field.</param>
- /// <returns></returns>
- public QueryStringQuery SetDefaultField (string field)
- {
- this.DefaultField = field;
- return this;
- }
- /// <summary>
- /// The query_string query can also run against multiple fields. The idea of running the query_string query against multiple
- /// fields is by internally creating several queries for the same query string, each with default_field that match the fields provided.
- /// Since several queries are generated, combining them can be automatically done either using a dis_max query or a simple bool query.
- /// </summary>
- /// <param name="fields">list with fields to perform the query on</param>
- /// <returns></returns>
- public QueryStringQuery SetFields(List<string> fields)
- {
- this.Fields = fields;
- return this;
- }
- /// <summary>
- /// The default operator used if no explicit operator is specified. For example,
- /// with a default operator of OR, the query capital of Hungary is translated to capital OR of OR Hungary,
- /// and with default operator of AND, the same query is translated to capital AND of AND
- /// Hungary.
- /// </summary>
- /// <param name="operator">The default value is OR</param>
- /// <returns></returns>
- public QueryStringQuery SetDefaultOperator(Operator @operator)
- {
- this.DefaultOperator = @operator;
- return this;
- }
- /// <summary>
- /// The analyzer name used to analyze the query string.
- /// </summary>
- /// <param name="analyzer">Custom analyzer name</param>
- /// <returns></returns>
- public QueryStringQuery SetAnalyzer(string analyzer)
- {
- this.Analyzer = analyzer;
- return this;
- }
- /// <summary>
- /// When set, * or ? are allowed as the first character.
- /// </summary>
- /// <param name="allowLeadingWildcard">Defaults to true.</param>
- /// <returns></returns>
- public QueryStringQuery SetAllowLeadingWildcard(bool allowLeadingWildcard)
- {
- this.AllowLeadingWildcard = allowLeadingWildcard;
- return this;
- }
- /// <summary>
- /// Whether terms of wildcard, prefix, fuzzy, and range queries are to be automatically lower-cased or
- /// not (since they are not analyzed).
- /// </summary>
- /// <param name="lowercaseExpendedTerms">Defaults to true.</param>
- /// <returns></returns>
- public QueryStringQuery SetLowercaseExpendedTerms(bool lowercaseExpendedTerms)
- {
- this.LowercaseExpendedTerms = lowercaseExpendedTerms;
- return this;
- }
- /// <summary>
- /// Set to true to enable position increments in result queries.
- /// </summary>
- /// <param name="enablePositionIncrements">Defaults to true.</param>
- /// <returns></returns>
- public QueryStringQuery SetEnablePositionIncrements(bool enablePositionIncrements)
- {
- this.EnablePositionIncrements = enablePositionIncrements;
- return this;
- }
- /// <summary>
- /// Set to true to enable position increments in result queries.
- /// </summary>
- /// <param name="fuzzyPrefixLength">Defaults to true.</param>
- /// <returns></returns>
- public QueryStringQuery SetFuzzyPrefixLength(int fuzzyPrefixLength)
- {
- this.FuzzyPrefixLength = fuzzyPrefixLength;
- return this;
- }
- /// <summary>
- /// Set the minimum similarity for fuzzy queries.
- /// </summary>
- /// <param name="fuzzyMinimumSimilarity">Defaults to 0.5</param>
- /// <returns></returns>
- public QueryStringQuery SetFuzzyMinimumSimilarity(double fuzzyMinimumSimilarity)
- {
- this.FuzzyMinimumSimilarity = fuzzyMinimumSimilarity;
- return this;
- }
- /// <summary>
- /// Sets the default slop for phrases. If zero, then exact phrase matches are required. Default value is 0
- /// </summary>
- /// <param name="phraseSlop">Default value is 0</param>
- /// <returns></returns>
- public QueryStringQuery SetPhraseSlop(double phraseSlop)
- {
- this.PhraseSlop = phraseSlop;
- return this;
- }
- /// <summary>
- /// Sets the boost value of the query
- /// </summary>
- /// <param name="boost">defaults to 1.0 </param>
- /// <returns></returns>
- public QueryStringQuery SetBoost(double boost)
- {
- this.Boost = boost;
- return this;
- }
- /// <summary>
- /// Should the queries be combined using dis_max (set it to true), or a bool query (set it to false).
- /// </summary>
- /// <param name="useDismax">Defaults to true</param>
- /// <returns></returns>
- public QueryStringQuery SetUseDisMax(bool useDismax)
- {
- this.UseDismax = useDismax;
- return this;
- }
- /// <summary>
- /// When using dis_max, the disjunction max tie breaker.
- /// </summary>
- /// <param name="tieBreaker">Defaults to 0</param>
- /// <returns></returns>
- public QueryStringQuery SetTieBreaker(int tieBreaker)
- {
- this.TieBreaker = tieBreaker;
- return this;
- }
-
- }
+ /// <summary>
+ /// By default, wildcards terms in a query string are not analyzed. By setting this value to true, a best effort will be made to analyze those as well.
+ /// </summary>
+ [JsonProperty("analyze_wildcard")]
+ public bool AnalyzeWildcard { get; set; }
+
+ /// <summary>
+ /// Default to false.
+ /// </summary>
+ [JsonProperty("auto_generate_phrase_queries")]
+ public bool AutoGeneratePhraseQueries { get; set; }
+ #endregion
+
+ public QueryStringQuery(string query)
+ {
+ this.Query = query;
+ this.DefaultOperator = Operator.OR;
+ this.AllowLeadingWildcard = true;
+ this.LowercaseExpendedTerms = true;
+ this.EnablePositionIncrements = true;
+ this.FuzzyMinimumSimilarity = 0.5;
+ this.Boost = 1.0;
+ this.UseDismax = true;
+ this.TieBreaker = 0;
+ }
+
+ public QueryStringQuery(List<string> fields, string query)
+ {
+ Fields = fields;
+ Query = query;
+ }
+
+ /// <summary>
+ /// The default field for query terms if no prefix field is specified.
+ /// </summary>
+ /// <param name="field">Defaults to the _all field.</param>
+ /// <returns></returns>
+ public QueryStringQuery SetDefaultField(string field)
+ {
+ this.DefaultField = field;
+ return this;
+ }
+ /// <summary>
+ /// The query_string query can also run against multiple fields. The idea of running the query_string query against multiple
+ /// fields is by internally creating several queries for the same query string, each with default_field that match the fields provided.
+ /// Since several queries are generated, combining them can be automatically done either using a dis_max query or a simple bool query.
+ /// </summary>
+ /// <param name="fields">list with fields to perform the query on</param>
+ /// <returns></returns>
+ public QueryStringQuery SetFields(List<string> fields)
+ {
+ this.Fields = fields;
+ return this;
+ }
+
+ public QueryStringQuery AddField(string field, int weight)
+ {
+ if (Fields == null) Fields = new List<string>();
+ Fields.Add(string.Format("{0}^{1}", field, weight));
+ return this;
+ }
+ /// <summary>
+ /// The default operator used if no explicit operator is specified. For example,
+ /// with a default operator of OR, the query capital of Hungary is translated to capital OR of OR Hungary,
+ /// and with default operator of AND, the same query is translated to capital AND of AND
+ /// Hungary.
+ /// </summary>
+ /// <param name="operator">The default value is OR</param>
+ /// <returns></returns>
+ public QueryStringQuery SetDefaultOperator(Operator @operator)
+ {
+ this.DefaultOperator = @operator;
+ return this;
+ }
+ /// <summary>
+ /// The analyzer name used to analyze the query string.
+ /// </summary>
+ /// <param name="analyzer">Custom analyzer name</param>
+ /// <returns></returns>
+ public QueryStringQuery SetAnalyzer(string analyzer)
+ {
+ this.Analyzer = analyzer;
+ return this;
+ }
+ /// <summary>
+ /// When set, * or ? are allowed as the first character.
+ /// </summary>
+ /// <param name="allowLeadingWildcard">Defaults to true.</param>
+ /// <returns></returns>
+ public QueryStringQuery SetAllowLeadingWildcard(bool allowLeadingWildcard)
+ {
+ this.AllowLeadingWildcard = allowLeadingWildcard;
+ return this;
+ }
+ /// <summary>
+ /// Whether terms of wildcard, prefix, fuzzy, and range queries are to be automatically lower-cased or
+ /// not (since they are not analyzed).
+ /// </summary>
+ /// <param name="lowercaseExpendedTerms">Defaults to true.</param>
+ /// <returns></returns>
+ public QueryStringQuery SetLowercaseExpendedTerms(bool lowercaseExpendedTerms)
+ {
+ this.LowercaseExpendedTerms = lowercaseExpendedTerms;
+ return this;
+ }
+ /// <summary>
+ /// Set to true to enable position increments in result queries.
+ /// </summary>
+ /// <param name="enablePositionIncrements">Defaults to true.</param>
+ /// <returns></returns>
+ public QueryStringQuery SetEnablePositionIncrements(bool enablePositionIncrements)
+ {
+ this.EnablePositionIncrements = enablePositionIncrements;
+ return this;
+ }
+ /// <summary>
+ /// Set to true to enable position increments in result queries.
+ /// </summary>
+ /// <param name="fuzzyPrefixLength">Defaults to true.</param>
+ /// <returns></returns>
+ public QueryStringQuery SetFuzzyPrefixLength(int fuzzyPrefixLength)
+ {
+ this.FuzzyPrefixLength = fuzzyPrefixLength;
+ return this;
+ }
+ /// <summary>
+ /// Set the minimum similarity for fuzzy queries.
+ /// </summary>
+ /// <param name="fuzzyMinimumSimilarity">Defaults to 0.5</param>
+ /// <returns></returns>
+ public QueryStringQuery SetFuzzyMinimumSimilarity(double fuzzyMinimumSimilarity)
+ {
+ this.FuzzyMinimumSimilarity = fuzzyMinimumSimilarity;
+ return this;
+ }
+ /// <summary>
+ /// Sets the default slop for phrases. If zero, then exact phrase matches are required. Default value is 0
+ /// </summary>
+ /// <param name="phraseSlop">Default value is 0</param>
+ /// <returns></returns>
+ public QueryStringQuery SetPhraseSlop(double phraseSlop)
+ {
+ this.PhraseSlop = phraseSlop;
+ return this;
+ }
+ /// <summary>
+ /// Sets the boost value of the query
+ /// </summary>
+ /// <param name="boost">defaults to 1.0 </param>
+ /// <returns></returns>
+ public QueryStringQuery SetBoost(double boost)
+ {
+ this.Boost = boost;
+ return this;
+ }
+ /// <summary>
+ /// Should the queries be combined using dis_max (set it to true), or a bool query (set it to false).
+ /// </summary>
+ /// <param name="useDismax">Defaults to true</param>
+ /// <returns></returns>
+ public QueryStringQuery SetUseDisMax(bool useDismax)
+ {
+ this.UseDismax = useDismax;
+ return this;
+ }
+ /// <summary>
+ /// When using dis_max, the disjunction max tie breaker.
+ /// </summary>
+ /// <param name="tieBreaker">Defaults to 0</param>
+ /// <returns></returns>
+ public QueryStringQuery SetTieBreaker(int tieBreaker)
+ {
+ this.TieBreaker = tieBreaker;
+ return this;
+ }
+
+ }
}
View
7 ElasticSearch.Client/QueryDSL/Query/TextQuery.cs
@@ -53,5 +53,12 @@ public TextQuery(string field, string text, Operator oPperator = Operator.OR, st
Operator = oPperator;
Analyzer = analyzer;
}
+
+ public TextQuery SetBoost(float boost)
+ {
+ Boost = boost;
+ return this;
+ }
+
}
}
View
BIN ElasticSearch.DataManager.suo
Binary file not shown.
View
2 ElasticSearch.DataManager/Dialogs/BulkIndex.cs
@@ -7,7 +7,7 @@
using System.Linq;
using System.Text;
using System.Windows.Forms;
-using ElasticSearch.Client.EMO;
+using ElasticSearch.Client.Domain;
namespace ElasticSearch.DataManager.Dialogs
{
View
2 ElasticSearch.DataManager/Form1.cs
@@ -14,7 +14,7 @@
using ElasticSearch.Client;
using ElasticSearch.Client.Admin;
using ElasticSearch.Client.Config;
-using ElasticSearch.Client.EMO;
+using ElasticSearch.Client.Domain;
using ElasticSearch.Client.Mapping;
using ElasticSearch.Client.Utils;
using ElasticSearch.DataManager.Dialogs;
View
2 ElasticSearch.Tests/Easy2Go.cs
@@ -24,7 +24,7 @@ public void SimpleTests()
var doc = client.Search(indexName, indexType, "c:d");
Console.WriteLine(doc.JsonString);
Assert.AreEqual(1, doc.GetHits().Hits.Count);
- Assert.AreEqual("b", doc.GetHits().Hits[0].Fields["a"]);
+ Assert.AreEqual("b", doc.GetHits().Hits[0].Source["a"]);
client.Delete(indexName, indexType, "testkey");
View
42 ElasticSearch.Tests/QueryDSL/QueryDSLTests.cs
@@ -127,7 +127,7 @@ public void TestWildcardQuery()
Assert.AreEqual(3, result.GetHits().Hits.Count);
foreach (var VARIABLE in result.GetHits().Hits)
{
- Console.WriteLine(VARIABLE.Fields["name"]);
+ Console.WriteLine(VARIABLE.Source["name"]);
}
Console.WriteLine("--");
@@ -137,7 +137,7 @@ public void TestWildcardQuery()
Assert.AreEqual(2, result.GetHits().Hits.Count);
foreach (var VARIABLE in result.GetHits().Hits)
{
- Console.WriteLine(VARIABLE.Fields["name"]);
+ Console.WriteLine(VARIABLE.Source["name"]);
}
}
@@ -150,7 +150,7 @@ public void TestBoolQuery()
var result = client.Search(index, "type" , query, 0, 5);
foreach (var VARIABLE in result.GetHits().Hits)
{
- Console.WriteLine(VARIABLE.Fields["name"]);
+ Console.WriteLine(VARIABLE.Source["name"]);
}
Assert.AreEqual(3, result.GetTotalCount());
Assert.AreEqual(3, result.GetHits().Hits.Count);
@@ -160,7 +160,7 @@ public void TestBoolQuery()
result = client.Search(index, "type" , query, 0, 5);
foreach (var VARIABLE in result.GetHits().Hits)
{
- Console.WriteLine(VARIABLE.Fields["name"]);
+ Console.WriteLine(VARIABLE.Source["name"]);
}
Assert.AreEqual(2, result.GetTotalCount());
Assert.AreEqual(2, result.GetHits().Hits.Count);
@@ -170,7 +170,7 @@ public void TestBoolQuery()
result = client.Search(index, "type" , query, 0, 5);
foreach (var VARIABLE in result.GetHits().Hits)
{
- Console.WriteLine(VARIABLE.Fields["name"]);
+ Console.WriteLine(VARIABLE.Source["name"]);
}
Assert.AreEqual(1, result.GetTotalCount());
Assert.AreEqual(1, result.GetHits().Hits.Count);
@@ -216,7 +216,7 @@ public void TestBoostingQuery()
var result = client.Search(index, "type" , query2, 0, 5);
foreach (var VARIABLE in result.GetHits().Hits)
{
- Console.WriteLine(VARIABLE.Fields["name"]);
+ Console.WriteLine(VARIABLE.Source["name"]);
}
}
@@ -267,7 +267,7 @@ public void TestCustomScoreQuery()
{
Console.WriteLine(o.ToString());
}
- Assert.AreEqual("",result.GetHits().Hits[0].Fields["name"]);
+ Assert.AreEqual("",result.GetHits().Hits[0].Source["name"]);
}
[Test,Ignore]
@@ -378,7 +378,7 @@ public void TestDisMaxQuery()
Assert.IsTrue(score0 > score1);
Assert.AreEqual(score1, score2);
Assert.AreEqual(3, result.GetTotalCount());
- Assert.AreEqual("d2", result.GetHits().Hits[0].Fields["id"]);
+ Assert.AreEqual("d2", result.GetHits().Hits[0].Source["id"]);
}
@@ -991,7 +991,7 @@ public void TestFilterdQuery()
result2 = client.Search(index, "type" , filteredQuery, 0, 5);
Assert.AreEqual(1, result2.GetTotalCount());
Assert.AreEqual(1, result2.GetHits().Hits.Count);
- Assert.AreEqual("张三丰",result2.GetHits().Hits[0].Fields["name"]);
+ Assert.AreEqual("张三丰",result2.GetHits().Hits[0].Source["name"]);
var boolQuery = new BoolQuery();
@@ -1004,7 +1004,7 @@ public void TestFilterdQuery()
result2 = client.Search(index, "type" , filteredQuery, 0, 5);
Assert.AreEqual(1, result2.GetTotalCount());
Assert.AreEqual(1, result2.GetHits().Hits.Count);
- Assert.AreEqual("张三丰", result2.GetHits().Hits[0].Fields["name"]);
+ Assert.AreEqual("张三丰", result2.GetHits().Hits[0].Source["name"]);
@@ -1013,7 +1013,7 @@ public void TestFilterdQuery()
result2 = client.Search(index, "type" , filteredQuery, 0, 5);
Assert.AreEqual(1, result2.GetTotalCount());
Assert.AreEqual(1, result2.GetHits().Hits.Count);
- Assert.AreEqual("张三", result2.GetHits().Hits[0].Fields["name"]);
+ Assert.AreEqual("张三", result2.GetHits().Hits[0].Source["name"]);
filteredQuery = new FilteredQuery(boolQuery, new TermFilter("type", "common"));
@@ -1059,7 +1059,7 @@ public void TestFilterdQuery()
result2 = client.Search(index, "type" , filteredQuery, 0, 5);
Assert.AreEqual(1, result2.GetTotalCount());
Assert.AreEqual(1, result2.GetHits().Hits.Count);
- Assert.AreEqual("张三", result2.GetHits().Hits[0].Fields["name"]);
+ Assert.AreEqual("张三", result2.GetHits().Hits[0].Source["name"]);
boolQuery.Should(new TermQuery("age", 25));
@@ -1084,7 +1084,7 @@ public void TestAndFilter()
var result2 = client.Search(index, "type" , q, 0, 5);
Assert.AreEqual(1, result2.GetTotalCount());
Assert.AreEqual(1, result2.GetHits().Hits.Count);
- Assert.AreEqual("张三", result2.GetHits().Hits[0].Fields["name"]);
+ Assert.AreEqual("张三", result2.GetHits().Hits[0].Source["name"]);
@@ -1093,7 +1093,7 @@ public void TestAndFilter()
result2 = client.Search(index, "type" , constantQuery, 0, 5);
Assert.AreEqual(1, result2.GetTotalCount());
Assert.AreEqual(1, result2.GetHits().Hits.Count);
- Assert.AreEqual("张三", result2.GetHits().Hits[0].Fields["name"]);
+ Assert.AreEqual("张三", result2.GetHits().Hits[0].Source["name"]);
}
@@ -1561,7 +1561,7 @@ public void TestNestedFilter()
var q = new FilteredQuery(new TermQuery("type","vip"), nestFilter);
var result=client.Search(index, "person", q, 0, 5);
Assert.AreEqual(1,result.GetTotalCount());
- Assert.AreEqual("jackson", result.GetHits().Hits[0].Fields["name"]);
+ Assert.AreEqual("jackson", result.GetHits().Hits[0].Source["name"]);
}
@@ -1574,16 +1574,16 @@ public void TestWithSort()
var result= client.Search(index, new string[] {"type"}, conq, new SortItem("age", SortType.Asc), 0, 5);
Assert.AreEqual(3,result.GetTotalCount());
- Assert.AreEqual(23,result.GetHits().Hits[0].Fields["age"]);
- Assert.AreEqual(24,result.GetHits().Hits[1].Fields["age"]);
- Assert.AreEqual(25,result.GetHits().Hits[2].Fields["age"]);
+ Assert.AreEqual(23,result.GetHits().Hits[0].Source["age"]);
+ Assert.AreEqual(24,result.GetHits().Hits[1].Source["age"]);
+ Assert.AreEqual(25,result.GetHits().Hits[2].Source["age"]);
result = client.Search(index, new string[] { "type" }, conq, new SortItem("age", SortType.Desc), 0, 5);
Assert.AreEqual(3, result.GetTotalCount());
- Assert.AreEqual(25, result.GetHits().Hits[0].Fields["age"]);
- Assert.AreEqual(24, result.GetHits().Hits[1].Fields["age"]);
- Assert.AreEqual(23, result.GetHits().Hits[2].Fields["age"]);
+ Assert.AreEqual(25, result.GetHits().Hits[0].Source["age"]);
+ Assert.AreEqual(24, result.GetHits().Hits[1].Source["age"]);
+ Assert.AreEqual(23, result.GetHits().Hits[2].Source["age"]);
}
#endregion

0 comments on commit e4dd143

Please sign in to comment.
Something went wrong with that request. Please try again.