예제 #1
0
 public string GetQueryExpression()
 {
     return(string.Format("{0}:({1}{2})",
                          Field,
                          LuceneHelpers.EscapeParenthesis(Expression),
                          string.Empty));
 }
예제 #2
0
        //public CustomFieldQuery(string queryExpression, string fieldName)
        //{
        //    Expression = queryExpression;
        //    Field = fieldName;
        //    Boost = null;
        //}

        //public CustomFieldQuery(string queryExpression, string fieldName, float boost)
        //{
        //    Expression = queryExpression;
        //    Field = fieldName;
        //    Boost = boost;
        //}

        public string GetQueryExpression()
        {
            if (this.Field == null)
            {
                return(string.Empty);
            }

            return(string.Format("{0}:({1}{2})", this.Field.Name, LuceneHelpers.EscapeParenthesis(Expression),
                                 this.Field.Boost.HasValue
                    ? string.Concat("^", this.Field.Boost.Value.ToString(CultureInfo.InvariantCulture).Replace(",", "."))
                    : string.Empty));
        }
예제 #3
0
        public string GetQueryExpression()
        {
            var stringBuilder = new StringBuilder();

            stringBuilder.Append(EventDateField.FieldName);
            stringBuilder.Append(":");
            stringBuilder.Append(this.Inclusive ? "[" : "{");
            stringBuilder.Append(LuceneHelpers.Escape(Regex.Replace(DateTime.Now.Date.ToString("u", System.Globalization.CultureInfo.InvariantCulture), "\\D", "")));
            stringBuilder.Append(" TO ");
            stringBuilder.Append(LuceneHelpers.Escape(Regex.Replace(DateTime.MaxValue.ToString("u", System.Globalization.CultureInfo.InvariantCulture), "\\D", "")));
            stringBuilder.Append(this.Inclusive ? "]" : "}");
            return(stringBuilder.ToString());
        }
예제 #4
0
        public virtual string GetQueryExpression()
        {
            var stringBuilder = new System.Text.StringBuilder();

            stringBuilder.Append(SearchSettings.Config.IndexingServiceFieldNameVirtualPath + ":(");
            foreach (string current in this.VirtualPathNodes)
            {
                stringBuilder.Append(LuceneHelpers.Escape(current.Replace(" ", "")));
                stringBuilder.Append("|");
            }
            if (stringBuilder.Length > 0)
            {
                stringBuilder.Remove(stringBuilder.Length - 1, 1);
            }
            stringBuilder.Append("*)");
            return(stringBuilder.ToString());
        }
예제 #5
0
        private static void AddFieldToQuery(GroupQuery groupQuery, string keyword, Field field, bool wildcard = true)
        {
            if (wildcard)
            {
                if (keyword.StartsWith("\"") && keyword.EndsWith("\""))
                {
                    var fieldQuery = new FieldQuery(keyword.Trim(), field);
                    groupQuery.QueryExpressions.Add(fieldQuery);
                    return;
                }

                if (keyword.Trim().Contains(" "))
                {
                    var words = keyword.Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    var query = new GroupQuery(LuceneOperator.OR);
                    foreach (string w in words)
                    {
                        if (w.Equals("and") || w.Equals("+"))
                        {
                            continue;
                        }
                        var s = w.Replace("\"", string.Empty).Trim();
                        var f = new FieldQuery(string.Format("{0}*", LuceneHelpers.Escape(s)), field);
                        query.QueryExpressions.Add(f);
                    }
                    groupQuery.QueryExpressions.Add(query);
                }
                else
                {
                    var fieldQuery = new FieldQuery(string.Format("{0}*", LuceneHelpers.Escape(keyword)), field);
                    groupQuery.QueryExpressions.Add(fieldQuery);
                }
            }
            else
            {
                var fieldQuery = new FieldQuery(string.Format("{0}", LuceneHelpers.Escape(keyword.Trim())), field);
                groupQuery.QueryExpressions.Add(fieldQuery);
            }
        }