Exemple #1
0
        /// <summary>
        /// Generates a logical block:
        /// var tsm = tran.TextSearch("MyTextSearchTable");
        /// tsm.Block("choose").And(new DBriize.TextSearch.BlockAnd("pill")).Or(tsm.BlockOr("blue red"))
        /// .GetDocumentIDs
        /// </summary>
        /// <param name="containsWords">space separated words to be used by "contains" logic or startswith if words were stored by full-match logic</param>
        /// <param name="fullMatchWords">space separated words to be used by "full-match" logic</param>
        /// <param name="ignoreOnEmptyParameters">Block will not be counted in intersection calculations if has empty FullMatch and Contains words</param>
        /// <returns></returns>
        public SBlock BlockOr(string containsWords = "", string fullMatchWords = "", bool ignoreOnEmptyParameters = false)
        {
            fullMatchWords = String.IsNullOrEmpty(fullMatchWords) ? "" : fullMatchWords;
            containsWords  = String.IsNullOrEmpty(containsWords) ? "" : containsWords;

            //SBlock sb = new BlockOr()
            //{
            //    _tsm = this,
            //    InternalBlockOperation = SBlock.eOperation.OR,
            //    BlockId = this.cntBlockId++,
            //    IsLogicalBlock = false
            //};

            SBlock sb = new BlockOr()
            {
                _tsm = this,
                InternalBlockOperation = SBlock.eOperation.OR,
                BlockId        = this.cntBlockId++,
                IsLogicalBlock = false
            };

            //First we add always but with the ignored flag
            if (ignoreOnEmptyParameters && String.IsNullOrEmpty(fullMatchWords) && String.IsNullOrEmpty(containsWords))
            {
                sb.Ignored = true;
            }

            Blocks.Add(sb.BlockId, sb);

            this.WordsPrepare(fullMatchWords.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Where(r => r.Length > 2), true, ref sb.ParsedWords);
            this.WordsPrepare(containsWords.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Where(r => r.Length > 2), false, ref sb.ParsedWords);

            toComputeWordsOrigin = true;
            return(sb);
        }
Exemple #2
0
        /// <summary>
        /// Generates a logical block:
        /// var tsm = tran.TextSearch("MyTextSearchTable");
        /// tsm.Block("choose").And(new DBriize.TextSearch.BlockAnd("pill")).Or(tsm.BlockOr("blue red"))
        /// .GetDocumentIDs
        /// </summary>
        /// <param name="containsWords">space separated words to be used by "contains" logic</param>
        /// <param name="fullMatchWords">space separated words to be used by "full-match" logic</param>
        /// <param name="ignoreOnEmptyParameters">Block will not be counted in intersection calculations if has empty FullMatch and Contains words</param>
        /// <returns></returns>
        public SBlock BlockOr(IEnumerable <string> containsWords, IEnumerable <string> fullMatchWords, bool ignoreOnEmptyParameters = false)
        {
            //SBlock sb = new BlockOr()
            //{
            //    _tsm = this,
            //    InternalBlockOperation = SBlock.eOperation.OR,
            //    BlockId = this.cntBlockId++,
            //    IsLogicalBlock = false
            //};

            SBlock sb = new BlockOr()
            {
                _tsm = this,
                InternalBlockOperation = SBlock.eOperation.OR,
                BlockId        = this.cntBlockId++,
                IsLogicalBlock = false
            };

            //First we add always but with the ignored flag
            if (ignoreOnEmptyParameters)
            {
                if ((containsWords == null || containsWords.Count() == 0 || containsWords.Where(r => r.Trim().Length > 0).Count() < 1)
                    &&
                    (fullMatchWords == null || fullMatchWords.Count() == 0 || fullMatchWords.Where(r => r.Trim().Length > 0).Count() < 1))
                {
                    sb.Ignored = true;
                }
            }

            Blocks.Add(sb.BlockId, sb);

            this.WordsPrepare(fullMatchWords, true, ref sb.ParsedWords);
            this.WordsPrepare(containsWords, false, ref sb.ParsedWords);

            toComputeWordsOrigin = true;
            return(sb);
        }
Exemple #3
0
        SBlock CreateBlock(SBlock block, eOperation operation, bool ignoreOnEmptyParameters = false)
        {
            if (_tsm == null)
            {
                throw new Exception("DBriize.Exception: first search block must be added via TextSearchTable");
            }

            //Returning parent block in case if this block must be ignored
            if (ignoreOnEmptyParameters && String.IsNullOrEmpty(block._fullMatchWords) && String.IsNullOrEmpty(block._containsWords))
            {
                return(this);
            }

            if (block._tsm == null)
            {
                //Creating real block
                block._tsm    = this._tsm;
                block.BlockId = this._tsm.cntBlockId++;
                this._tsm.WordsPrepare(block._fullMatchWords.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Where(r => r.Length > 2), true, ref block.ParsedWords);
                this._tsm.WordsPrepare(block._containsWords.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Where(r => r.Length > 2), false, ref block.ParsedWords);
                this._tsm.toComputeWordsOrigin  = true;
                this._tsm.Blocks[block.BlockId] = block;
            }

            //Creating logical block
            SBlock b = null;

            switch (operation)
            {
            case eOperation.AND:
                b = new BlockAnd();
                break;

            case eOperation.OR:
                b = new BlockOr();
                break;

            case eOperation.XOR:
                b = new BlockXOR();
                break;

            case eOperation.EXCLUDE:
                b = new BlockEXCLUDE();
                break;
            }

            b._tsm                = this._tsm;
            b.BlockId             = this._tsm.cntBlockId++;
            b.LeftBlockId         = BlockId;
            b.RightBlockId        = block.BlockId;
            b.TransBlockOperation = operation;

            //SBlock b = new SBlock()
            //{
            //    _tsm = this._tsm,
            //    BlockId = this._tsm.cntBlockId++,
            //    LeftBlockId = this.BlockId,
            //    RightBlockId = block.BlockId,
            //    TransBlockOperation = operation
            //};

            this._tsm.Blocks[b.BlockId] = b;

            return(b);
        }