Beispiel #1
0
        /// <summary>
        /// Appends the field.
        /// </summary>
        /// <param name="key">The attribute key.</param>
        /// <param name="value">The attribute value.</param>
        /// <param name="matchVariant">The match variant.</param>
        public void AppendField(string key, string value, MatchVariant matchVariant)
        {
            FieldQuery fldQuery = new FieldQuery(key, value, matchVariant);
            QueryNode  node     = new QueryNode(fldQuery);

            this.AddNode(node);
        }
        /// <summary>
        /// Gets the match variant.
        /// </summary>
        /// <param name="variant">The variant.</param>
        /// <returns>Returns string representing match variant.</returns>
        protected virtual string GetMatchVariant(MatchVariant variant)
        {
            string result = string.Empty;

            switch (variant)
            {
            case MatchVariant.Exactly:
                result = "=";
                break;

            case MatchVariant.GreaterThan:
                result = ">";
                break;

            case MatchVariant.GreaterThanOrEqual:
                result = ">=";
                break;

            case MatchVariant.LessThan:
                result = "<";
                break;

            case MatchVariant.LessThanOrEqual:
                result = "<=";
                break;

            case MatchVariant.NotEquals:
                result = "!=";
                break;
            }

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Appends the subquery.
        /// </summary>
        /// <param name="key">The attribute key.</param>
        /// <param name="value">The attribute value.</param>
        /// <param name="matchVariant">The match variant.</param>
        public void AppendAttribute(string key, string value, MatchVariant matchVariant)
        {
            AttributeQuery query = new AttributeQuery(key, value, matchVariant);
            QueryNode      node  = new QueryNode(query);

            this.AddNode(node);
        }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SubQuery"/> class.
 /// </summary>
 /// <param name="key">The field key.</param>
 /// <param name="value">The value.</param>
 /// <param name="matchVariant">The match variant.</param>
 protected SubQuery(string key, string value, MatchVariant matchVariant)
 {
   this.Key = key;
   this.Value = value;
   this.MatchVariant = matchVariant;
 }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FieldQuery"/> class.
 /// </summary>
 /// <param name="key">The field key.</param>
 /// <param name="value">The value.</param>
 /// <param name="matchVariant">The match variant.</param>
 public FieldQuery(string key, string value, MatchVariant matchVariant)
   : base(key, value, matchVariant)
 {
 }
Beispiel #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SubQuery"/> class.
 /// </summary>
 /// <param name="key">The field key.</param>
 /// <param name="value">The value.</param>
 /// <param name="matchVariant">The match variant.</param>
 protected SubQuery(string key, string value, MatchVariant matchVariant)
 {
     this.Key          = key;
     this.Value        = value;
     this.MatchVariant = matchVariant;
 }
    protected virtual LuceneSearch.TermRangeQuery GetRangeQuery(string key, string value, MatchVariant variant)
    {
      switch (variant)
      {
        case MatchVariant.GreaterThan:
          return new LuceneSearch.TermRangeQuery(key, value, null, false, true);
        case MatchVariant.GreaterThanOrEqual:
          return new LuceneSearch.TermRangeQuery(key, value, null, true, true);
        case MatchVariant.LessThan:
          return new LuceneSearch.TermRangeQuery(key, null, value, true, false);
        case MatchVariant.LessThanOrEqual:
          return new LuceneSearch.TermRangeQuery(key, null, value, true, true);
      }

      return null;
    }
    /// <summary>
    /// Adds the content sub query.
    /// </summary>
    /// <param name="query">The boolean query.</param>
    /// <param name="key">The field key.</param>
    /// <param name="value">The field value.</param>
    /// <param name="matchVariant">The match variant.</param>
    /// <param name="condition">The condition.</param>
    /// <param name="isFirst">if set to <c>true</c> [is first].</param>
    private void AddContentSubQuery(LuceneSearch.BooleanQuery query, string key, string value, MatchVariant matchVariant, QueryCondition condition)
    {
      if (matchVariant == MatchVariant.NotEquals)
      {
        query.Add(new LuceneSearch.TermQuery(new Term(key, value)), LuceneSearch.Occur.MUST_NOT);
        return;
      }

      LuceneSearch.Occur occurrence = this.GetOccur(condition);

      LuceneSearch.TermRangeQuery rangeQuery = this.GetRangeQuery(key, value, matchVariant);
      if (rangeQuery != null)
      {
        query.Add(rangeQuery, occurrence);
        return;
      }

      string[] keywords = value.Split(' ');
      if (keywords.Length > 1)
      {
        LuceneSearch.PhraseQuery phraseQuery = new Lucene.Net.Search.PhraseQuery();

        foreach (string keyword in keywords)
        {
          phraseQuery.Add(new Term(key, keyword));
        }

        query.Add(phraseQuery, occurrence);
      }
      else if (matchVariant == MatchVariant.Like)
      {
        query.Add(new LuceneSearch.WildcardQuery(new Term(key, value + "*")), occurrence);
      }
      else
      {
        query.Add(new LuceneSearch.TermQuery(new Term(key, value)), occurrence);
      }
    }
Beispiel #9
0
 /// <summary>
 /// Appends the field.
 /// </summary>
 /// <param name="key">The attribute key.</param>
 /// <param name="value">The attribute value.</param>
 /// <param name="matchVariant">The match variant.</param>
 public void AppendField(string key, string value, MatchVariant matchVariant)
 {
   FieldQuery fldQuery = new FieldQuery(key, value, matchVariant);
   QueryNode node = new QueryNode(fldQuery);
   this.AddNode(node);
 }
Beispiel #10
0
 /// <summary>
 /// Appends the subquery.
 /// </summary>
 /// <param name="key">The attribute key.</param>
 /// <param name="value">The attribute value.</param>
 /// <param name="matchVariant">The match variant.</param>
 public void AppendAttribute(string key, string value, MatchVariant matchVariant)
 {
   AttributeQuery query = new AttributeQuery(key, value, matchVariant);
   QueryNode node = new QueryNode(query);
   this.AddNode(node);
 }
Beispiel #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FieldQuery"/> class.
 /// </summary>
 /// <param name="key">The field key.</param>
 /// <param name="value">The value.</param>
 /// <param name="matchVariant">The match variant.</param>
 public FieldQuery(string key, string value, MatchVariant matchVariant)
     : base(key, value, matchVariant)
 {
 }
    /// <summary>
    /// Gets the match variant.
    /// </summary>
    /// <param name="variant">The variant.</param>
    /// <returns>Returns string representing match variant.</returns>
    protected virtual string GetMatchVariant(MatchVariant variant)
    {
      string result = string.Empty;
      switch (variant)
      {
        case MatchVariant.Exactly:
          result = "=";
          break;
        case MatchVariant.GreaterThan:
          result = ">";
          break;
        case MatchVariant.GreaterThanOrEqual:
          result = ">=";
          break;
        case MatchVariant.LessThan:
          result = "<";
          break;
        case MatchVariant.LessThanOrEqual:
          result = "<=";
          break;
        case MatchVariant.NotEquals:
          result = "!=";
          break;
      }

      return result;
    }
Beispiel #13
0
        protected virtual LuceneSearch.TermRangeQuery GetRangeQuery(string key, string value, MatchVariant variant)
        {
            switch (variant)
            {
            case MatchVariant.GreaterThan:
                return(new LuceneSearch.TermRangeQuery(key, value, null, false, true));

            case MatchVariant.GreaterThanOrEqual:
                return(new LuceneSearch.TermRangeQuery(key, value, null, true, true));

            case MatchVariant.LessThan:
                return(new LuceneSearch.TermRangeQuery(key, null, value, true, false));

            case MatchVariant.LessThanOrEqual:
                return(new LuceneSearch.TermRangeQuery(key, null, value, true, true));
            }

            return(null);
        }
Beispiel #14
0
        /// <summary>
        /// Adds the content sub query.
        /// </summary>
        /// <param name="query">The boolean query.</param>
        /// <param name="key">The field key.</param>
        /// <param name="value">The field value.</param>
        /// <param name="matchVariant">The match variant.</param>
        /// <param name="condition">The condition.</param>
        /// <param name="isFirst">if set to <c>true</c> [is first].</param>
        private void AddContentSubQuery(LuceneSearch.BooleanQuery query, string key, string value, MatchVariant matchVariant, QueryCondition condition)
        {
            if (matchVariant == MatchVariant.NotEquals)
            {
                query.Add(new LuceneSearch.TermQuery(new Term(key, value)), LuceneSearch.Occur.MUST_NOT);
                return;
            }

            LuceneSearch.Occur occurrence = this.GetOccur(condition);

            LuceneSearch.TermRangeQuery rangeQuery = this.GetRangeQuery(key, value, matchVariant);
            if (rangeQuery != null)
            {
                query.Add(rangeQuery, occurrence);
                return;
            }

            string[] keywords = value.Split(' ');
            if (keywords.Length > 1)
            {
                LuceneSearch.PhraseQuery phraseQuery = new Lucene.Net.Search.PhraseQuery();

                foreach (string keyword in keywords)
                {
                    phraseQuery.Add(new Term(key, keyword));
                }

                query.Add(phraseQuery, occurrence);
            }
            else if (matchVariant == MatchVariant.Like)
            {
                query.Add(new LuceneSearch.WildcardQuery(new Term(key, value + "*")), occurrence);
            }
            else
            {
                query.Add(new LuceneSearch.TermQuery(new Term(key, value)), occurrence);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AttributeQuery"/> class.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="value">The value.</param>
 /// <param name="matchVariant">The match variant.</param>
 public AttributeQuery(string key, string value, MatchVariant matchVariant) : base(key, value, matchVariant)
 {
 }
Beispiel #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AttributeQuery"/> class.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="value">The value.</param>
 /// <param name="matchVariant">The match variant.</param>
 public AttributeQuery(string key, string value, MatchVariant matchVariant) : base(key, value, matchVariant)
 {
 }