public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { TermsQuery term = (TermsQuery)value; //{ "terms" : { "tags" : [ "blue", "pill" ], "minimum_match" : 1 }} if (term != null) { var stringBuilder = new StringBuilder(); stringBuilder.Append("{ \"terms\" : { \"" + term.Field + "\" : ["); var i = 0; foreach (var t in term.Values) { if (i > 0) { stringBuilder.Append(","); } stringBuilder.Append("\"" + t + "\""); i++; } stringBuilder.Append("], \"minimum_match\" : " + term.MinimumMatch + " }}"); writer.WriteRawValue(stringBuilder.ToString()); } }
public void TestTermsQueryWithMinuMatch() { var query = new TermsQuery("gender",2, "true", "false"); var result = client.Search(index, "type" , query, 0, 5); Assert.AreEqual(0, result.GetTotalCount()); Assert.AreEqual(0, result.GetHits().Hits.Count); var item = new IndexItem("type","addition_key1"); item.Add("name", Guid.NewGuid().ToString()); item.Add("id", 2012); item.Add("gender", true); item.Add("gender", false); client.Index(index, item); Thread.Sleep(1000); result = client.Search(index, "type" , query, 0, 5); Assert.AreEqual(1, result.GetTotalCount()); Assert.AreEqual(1, result.GetHits().Hits.Count); }
public void TestTermsQuery() { var query = new TermsQuery("gender", "true","false"); var result = client.Search(index, "type" , query, 0, 5); Assert.AreEqual(100, result.GetTotalCount()); Assert.AreEqual(5, result.GetHits().Hits.Count); }
public void TestMatchAllFilter() { var query = new TermQuery("gender","true");//new TermsQuery("gender", "true", "false"); var filterQuery = new FilteredQuery(query, new MatchAllFilter()); var result = client.Search(index, "type" , filterQuery, 0, 5); Assert.AreEqual(50, result.GetTotalCount()); Assert.AreEqual(5, result.GetHits().Hits.Count); var query1 = new TermsQuery("gender", "true"); filterQuery = new FilteredQuery(query1, new MatchAllFilter()); result = client.Search(index, "type" , filterQuery, 0, 5); Assert.AreEqual(50, result.GetTotalCount()); Assert.AreEqual(5, result.GetHits().Hits.Count); }