コード例 #1
0
        /// <summary>
        /// The text_phrase_prefix is the same as text_phrase, expect it allows for prefix matches on the last term
        /// in the text
        /// </summary>
        public QueryContainer MatchPhrasePrefix(Action <MatchPhrasePrefixQueryDescriptor <T> > selector)
        {
            var query = new MatchPhrasePrefixQueryDescriptor <T>();

            selector(query);

            return(this.New(query, q => q.Match = query));
        }
コード例 #2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var j = JObject.Load(reader);

            if (!j.HasValues)
            {
                return(null);
            }

            var firstProp = j.Properties().FirstOrDefault();

            if (firstProp == null)
            {
                return(null);
            }

            var field = firstProp.Name;
            var jo    = firstProp.Value.Value <JObject>();

            if (jo == null)
            {
                return(null);
            }

            JToken v    = null;
            string type = null;

            if (jo.TryGetValue("type", out v))
            {
                type = v.Value <string>();
            }

            IMatchQuery fq = null;

            if (type.IsNullOrEmpty())
            {
                fq = new MatchQueryDescriptor <object>();
            }
            else if (type == "phrase")
            {
                fq = new MatchPhraseQueryDescriptor <object>();
            }
            else if (type == "phrase_prefix")
            {
                fq = new MatchPhrasePrefixQueryDescriptor <object>();
            }
            else
            {
                return(null);
            }

            fq.Field           = field;
            fq.Boost           = GetPropValue <double?>(jo, "boost");
            fq.Analyzer        = GetPropValue <string>(jo, "analyzer");
            fq.CutoffFrequency = GetPropValue <double?>(jo, "cutoff_frequency");
            fq.Fuzziness       = GetPropValue <double?>(jo, "fuzziness");
            fq.Lenient         = GetPropValue <bool?>(jo, "lenient");
            fq.MaxExpansions   = GetPropValue <int?>(jo, "max_expansions");
            fq.PrefixLength    = GetPropValue <int?>(jo, "prefix_length");
            fq.Query           = GetPropValue <string>(jo, "query");
            fq.Slop            = GetPropValue <int?>(jo, "slop");

            var rewriteString = GetPropValue <string>(jo, "rewrite");

            if (!rewriteString.IsNullOrEmpty())
            {
                fq.Rewrite = rewriteString.ToEnum <RewriteMultiTerm>();
            }

            var operatorString = GetPropValue <string>(jo, "operator");

            if (!rewriteString.IsNullOrEmpty())
            {
                fq.Operator = operatorString.ToEnum <Operator>();
            }

            return(fq);
        }