Example #1
0
 private LibraryFilter(LibraryFilter parent, String searchString)
 {
     _parent       = parent;
     _searchString = searchString;
     Initialize();
 }
Example #2
0
        private void Initialize()
        {
            String s = _searchString;

            s = s.ToLowerInvariant();

            s = s.Replace(" and ", "&");
            s = s.Replace(" or ", "|");

            s = s.Replace(" like ", "~");
            s = s.Replace(" equals ", "=");

            s = s.Replace(" not ", "-");

            var substrings = RemoveParentheses(ref s);

            // AND operation
            var array = s.Split('&');
            int i;

            for (i = 0; i < array.Length; i++)
            {
                array[i] = array[i].Trim();
            }
            if (array.Length > 1)
            {
                _operation = Operation.And;
                RestoreParentheses(ref array, substrings);
                foreach (var ss in array)
                {
                    var child = new LibraryFilter(this, ss);
                    _children.Add(child);
                }
                return;
            }

            // OR operation
            array = s.Split('|');
            for (i = 0; i < array.Length; i++)
            {
                array[i] = array[i].Trim();
            }
            if (array.Length > 1)
            {
                _operation = Operation.Or;
                RestoreParentheses(ref array, substrings);
                foreach (var ss in array)
                {
                    var child = new LibraryFilter(this, ss);
                    _children.Add(child);
                }
                return;
            }



            RestoreParentheses(ref array, substrings);
            s = array[0];

            //eliminate outward parentheses if any
            int par = s.IndexOf('(');

            if (par >= 0)
            {
                _sign = GetSign(ref s);
                if (!_sign)
                {
                    par = s.IndexOf('(');
                }

                s = s.Remove(par, 1);

                int lpar = s.LastIndexOf(')');
                if (lpar < 0)
                {
                    return;           //mismatched parentheses
                }
                s = s.Remove(lpar, 1);

                s = s.Trim();

                _operation = Operation.Sign;
                var child = new LibraryFilter(this, s);
                _children.Add(child);
                return;
            }

            _sign = GetSign(ref s);

            // Equals Evaluation
            array = s.Split('=');
            if (array.Length > 2)
            {
                return;                   // bad request
            }
            if (array.Length == 2)
            {
                _operation = Operation.TestEquals;
                _field     = array[0].Trim();
                _value     = array[1].Trim();
                return;
            }

            // Contains Evaluation
            _operation = Operation.TestContains;

            array = s.Split('~');
            if (array.Length > 2)
            {
                return;                   // bad request
            }
            if (array.Length == 2)
            {
                _field = array[0].Trim();
                _value = array[1].Trim();
                return;
            }

            _field = "path";
            _value = s.Trim();
        }
Example #3
0
 public LibraryFilter(String searchString)
 {
     _parent       = null;
     _searchString = searchString;
     Initialize();
 }