Exemplo n.º 1
0
        /// <summary>
        /// Gets Solr parameters for all defined query options
        /// </summary>
        /// <param name="Query"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public IEnumerable <KeyValuePair <string, string> > GetAllParameters(ISolrQuery Query, QueryOptions options)
        {
            yield return(KV.Create("q", querySerializer.Serialize(Query)));

            if (options == null)
            {
                yield break;
            }

            foreach (var p in GetCommonParameters(options))
            {
                yield return(p);
            }

            if (options.OrderBy != null && options.OrderBy.Count > 0)
            {
                yield return(KV.Create("sort", string.Join(",", options.OrderBy.Select(x => x.ToString()).ToArray())));
            }

            foreach (var p in GetTermsParameters(options))
            {
                yield return(p);
            }

            foreach (var p in GetTermVectorQueryOptions(options))
            {
                yield return(p);
            }
        }
        public override string Serialize(SolrMultipleCriteriaQuery q)
        {
            var queryBuilder = new StringBuilder();

            foreach (var query in q.Queries)
            {
                if (query == null)
                {
                    continue;
                }
                var sq = serializer.Serialize(query);
                if (string.IsNullOrEmpty(sq))
                {
                    continue;
                }
                if (queryBuilder.Length > 0)
                {
                    queryBuilder.AppendFormat(" {0} ", q.Oper);
                }
                queryBuilder.Append(sq);
            }
            var queryString = queryBuilder.ToString();

            if (!string.IsNullOrEmpty(queryString))
            {
                queryString = "(" + queryString + ")";
            }
            return(queryString);
        }
Exemplo n.º 3
0
 public override string Serialize(SolrQueryInList q)
 {
     if (string.IsNullOrEmpty(q.FieldName) || q.List == null || !q.List.Any())
     {
         return(null);
     }
     return("(" + string.Join(" OR ", q.List.Select(l => serializer.Serialize(new SolrQueryByField(q.FieldName, l))).ToArray()) + ")");
 }
        public override string Serialize(SolrQueryInList q)
        {
            if (string.IsNullOrEmpty(q.FieldName) || q.List == null || !q.List.Any())
            {
                return(null);
            }

            var array = q.List.Select(x => "(" + QueryByFieldSerializer.Quote(x) + ")").ToArray();

            return("(" + serializer.Serialize(new SolrQueryByField(QueryByFieldSerializer.EscapeSpaces(q.FieldName), string.Join(" OR ", array))
            {
                Quoted = false
            }) + ")");
        }
 public IEnumerable <XElement> ToXmlNode()
 {
     if (ids != null)
     {
         foreach (var i in ids)
         {
             yield return(new XElement("id", i));
         }
     }
     if (query != null)
     {
         var value = querySerializer.Serialize(query);
         yield return(new XElement("query", value));
     }
 }
Exemplo n.º 6
0
        public IEnumerable <XmlNode> ToXmlNode()
        {
            var xml = new XmlDocument();

            if (ids != null)
            {
                foreach (var i in ids)
                {
                    var node = xml.CreateElement("id");
                    node.InnerText = i;
                    yield return(node);
                }
            }
            if (query != null)
            {
                var queryNode = xml.CreateElement("query");
                queryNode.InnerText = querySerializer.Serialize(query);
                yield return(queryNode);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets Solr parameters for all defined query options
        /// </summary>
        /// <param name="Query"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public IEnumerable <KeyValuePair <string, string> > GetAllParameters(ISolrQuery Query, QueryOptions options)
        {
            var q = querySerializer.Serialize(Query);

            if (q.Length > 0)
            {
                yield return(KV.Create("q", q));
            }

            if (options == null)
            {
                yield break;
            }

            foreach (var p in GetCommonParameters(options))
            {
                yield return(p);
            }

            if (options.OrderBy != null && options.OrderBy.Count > 0)
            {
                yield return(KV.Create("sort", string.Join(",", options.OrderBy.Select(x => x.ToString()).ToArray())));
            }

            foreach (var p in GetHighlightingParameters(options))
            {
                yield return(p);
            }

            foreach (var p in GetSpellCheckingParameters(options))
            {
                yield return(p);
            }

            foreach (var p in GetTermsParameters(options))
            {
                yield return(p);
            }

            if (options.MoreLikeThis != null)
            {
                foreach (var p in GetMoreLikeThisParameters(options.MoreLikeThis))
                {
                    yield return(p);
                }
            }

            foreach (var p in GetStatsQueryOptions(options))
            {
                yield return(p);
            }

            foreach (var p in GetCollapseQueryOptions(options))
            {
                yield return(p);
            }

            foreach (var p in GetTermVectorQueryOptions(options))
            {
                yield return(p);
            }

            foreach (var p in GetGroupingQueryOptions(options))
            {
                yield return(p);
            }

            foreach (var p in GetCollapseExpandOptions(options.CollapseExpand, querySerializer.Serialize))
            {
                yield return(p);
            }

            foreach (var p in GetClusteringParameters(options))
            {
                yield return(p);
            }
        }
Exemplo n.º 8
0
 /// <inheritdoc />
 public override string Serialize(SolrQueryBoost q)
 {
     return(string.Format("({0})^{1}", serializer.Serialize(q.Query), q.Factor.ToString(CultureInfo.InvariantCulture.NumberFormat)));
 }
Exemplo n.º 9
0
 public override string Serialize(SolrRequiredQuery q)
 {
     return("+" + serializer.Serialize(q.Query));
 }
Exemplo n.º 10
0
 public override string Serialize(SolrNotQuery q)
 {
     return("-" + serializer.Serialize(q.Query));
 }
Exemplo n.º 11
0
 public override IEnumerable <KeyValuePair <string, string> > Serialize(SolrFacetQuery q)
 {
     yield return(new KeyValuePair <string, string>("facet.query", serializer.Serialize(q.Query)));
 }
Exemplo n.º 12
0
 public override string Serialize(SolrHasValueQuery q)
 {
     return(serializer.Serialize(new SolrQueryByRange <string>(q.Field, "*", "*")));
 }
Exemplo n.º 13
0
 public override string Serialize(LocalParams.LocalParamsQuery q)
 {
     return(q.Local + serializer.Serialize(q.Query));
 }
Exemplo n.º 14
0
 /// <inheritdoc />
 public override string Serialize(SolrConstantScoreQuery q)
 {
     return(string.Format("({0})^={1}", serializer.Serialize(q.Query), q.Score.ToString(CultureInfo.InvariantCulture.NumberFormat)));
 }
Exemplo n.º 15
0
        /// <summary>
        /// Gets Solr parameters for all defined query options
        /// </summary>
        /// <param name="Query"></param>
        /// <param name="Options"></param>
        /// <returns></returns>
        public IEnumerable <KeyValuePair <string, string> > GetAllParameters(ISolrQuery Query, QueryOptions Options)
        {
            yield return(KVP("q", querySerializer.Serialize(Query)));

            if (Options != null)
            {
                if (Options.Start.HasValue)
                {
                    yield return(KVP("start", Options.Start.ToString()));
                }
                var rows = Options.Rows.HasValue ? Options.Rows.Value : DefaultRows;
                yield return(KVP("rows", rows.ToString()));

                if (Options.OrderBy != null && Options.OrderBy.Count > 0)
                {
                    yield return(KVP("sort", string.Join(",", Options.OrderBy.Select(x => x.ToString()).ToArray())));
                }

                if (Options.Fields != null && Options.Fields.Count > 0)
                {
                    yield return(KVP("fl", string.Join(",", Options.Fields.ToArray())));
                }

                foreach (var p in GetHighlightingParameters(Options))
                {
                    yield return(p);
                }

                foreach (var p in GetFilterQueries(Options))
                {
                    yield return(p);
                }

                foreach (var p in GetSpellCheckingParameters(Options))
                {
                    yield return(p);
                }

                foreach (var p in GetMoreLikeThisParameters(Options))
                {
                    yield return(p);
                }

                foreach (var p in GetFacetFieldOptions(Options))
                {
                    yield return(p);
                }

                foreach (var p in GetStatsQueryOptions(Options))
                {
                    yield return(p);
                }

                foreach (var p in GetCollapseQueryOptions(Options))
                {
                    yield return(p);
                }

                if (Options.ExtraParams != null)
                {
                    foreach (var p in Options.ExtraParams)
                    {
                        yield return(p);
                    }
                }
            }
        }