示例#1
0
        protected IndexSequence SearchField(string field, string value)
        {
            try
            {
                IndexSequence seq    = this[FIELD_NAME_CHAR + field.ToLower()];
                IndexSequence newseq = SearchWord(value.ToLower());
                seq.R = -1;
                return(seq * newseq);
            }
            catch (Exception e)
            {
                /* NOT FOUND */
            }

            return(new IndexSequence());

            /*
             *          var _matches = Regex.Matches(value, @"\b\w+\b");
             *          IndexSequence orVals = new IndexSequence();
             *              IndexSequence seq = this[FIELD_NAME_CHAR + field.ToLower()];
             *              foreach (var match in _matches)
             *              {
             *                  IndexSequence newseq = SearchWord(match.ToString().ToLower());
             *                  newseq.R = -1;
             *                  newseq *= seq;
             *                  orVals += newseq;
             *              }
             *
             *          return (orVals);
             */
        }
示例#2
0
 public IndexSequence(IndexSequence seq)
 {
     self = new List <ushort>(seq.self);
 }
示例#3
0
 public SeqEnumerator(IndexSequence seq)
 {
     _seq = seq;
     Reset();
 }
示例#4
0
        protected IndexSequence SearchWord(string word)
        {
            //      if (word.Length < MIN_WORD_LENGTH) return (new IndexSequence(/* Empty */));
            string stemmed = word;
            bool   bExact  = false;


            if ((word.ToUpper().Equals(word)) && (bKeepForms))
            {
                bExact = true;
            }
            word = word.ToLower();

            IndexSequence total = null;

            string[] words = { word };

            if (word.IndexOf('_') >= 0)
            {
                if (bKeepForms)
                {
                    bExact = true;
                    words  = GetLikeWords(word);
                }
                else
                {
                    return(new IndexSequence());
                }
            }

            foreach (string wword in words)
            {
                try
                {
                    IndexSequence res   = new IndexSequence();
                    var           codes = GetWordCodes(wword).Select((c) => c.code);
                    if (codes.Count() > 0)
                    {
                        var selfcodes = codes.Where((s) => Regex.IsMatch(s.Substring(0, 1), @"\w"));
                        var knowcodes = codes.Except(selfcodes);
                        // search for know or exact words if any
                        foreach (string code in (!bExact ? (knowcodes.Count() > 0 ? knowcodes : selfcodes.Take(1)) : selfcodes.Take(1)))
                        {
                            if (self.Keys.Contains(code))
                            {
                                res = this[code];

                                if (total == null)
                                {
                                    total = res;
                                }
                                else
                                {
                                    total += res;
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error search word: " + e.Message);
                }
            }
            if (total == null)
            {
                total = new IndexSequence();
            }

            if (bExact)
            {
                total.R = -1;
            }
            return(total);
        }