예제 #1
0
	    public void TestQueryString()
	    {
	        var query = new QueryStringQuery("gender:true");
	        var result = client.Search(index, "type" , query, 0, 5);
	        Assert.AreEqual(50, result.GetTotalCount());
	        Assert.AreEqual(5, result.GetHits().Hits.Count);
	    }
예제 #2
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            QueryStringQuery term = (QueryStringQuery)value;

            if (term != null)
            {
                var stringBuilder = new StringBuilder();
                stringBuilder.Append("{query_string:{ ");
                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 + "\" ");
                if (!string.IsNullOrEmpty(term.Analyzer))
                {
                    stringBuilder.Append(",\"analyzer\":\"" + term.Analyzer + "\" ");
                }
                stringBuilder.Append("}}");

                //TODO 完成更多参数+ 参数判断

                writer.WriteRawValue(stringBuilder.ToString());
            }
        }
예제 #3
0
        public void TestConstantSocreWithStringQuery()
        {
            var query = new QueryStringQuery("gender:true");

            var constanQuery = new ConstantScoreQuery(query);
            
            var result = client.Search(index, "type" , constanQuery, 0, 5);
            
            Assert.AreEqual(50, result.GetTotalCount());
            Assert.AreEqual(5, result.GetHits().Hits.Count);
        }