Пример #1
0
        protected void Search(SearchCriterion criterion)
        {
            IList<SnippetInMemory> searchIn = null;
            // we only search in the last results if it's an And or a Not
            if (criterion.ConcatWithLast == SearchTypeConcat.And || criterion.ConcatWithLast == SearchTypeConcat.Not)
                searchIn = lastResults;
            // otherwsie we search in the original universe of snippets
            else if (criterion.ConcatWithLast == SearchTypeConcat.Or || criterion.ConcatWithLast == SearchTypeConcat.None)
                searchIn = model.snippets;
            else
                throw new NotSupportedException("Unsupported search type, sorry!");

            List<SnippetInMemory> results = new List<SnippetInMemory>();

            // if it's an OR or a NOT, bring the old results forward
            if (criterion.ConcatWithLast == SearchTypeConcat.Or || criterion.ConcatWithLast == SearchTypeConcat.Not)
                results.AddRange(lastResults);

            foreach (SnippetInMemory snippet in searchIn)
            {
                // AND and OR both need the snippet to not be present already (to not double up) and to match the criterion.
                if (criterion.ConcatWithLast != SearchTypeConcat.Not && !results.Contains(snippet) && snippet.Matches(criterion))
                {
                    results.Add(snippet);
                }
                // the not needs the snippet to already be there to remove it, and then if it matches the criteria we remove it
                else if (criterion.ConcatWithLast == SearchTypeConcat.Not && results.Contains(snippet) && snippet.Matches(criterion))
                {
                    results.Remove(snippet);
                }
            }

            lastResults = results;
        }
 public SearchCriterion GetCriterion()
 {
     SearchCriterion retVal = new SearchCriterion();
     retVal.ConcatWithLast = (SearchTypeConcat)Int32.Parse(GetValue("ConcatWithLast", criterionText));
     int ignoreCase = Int32.Parse(GetValue("IgnoreCase", criterionText));
     retVal.IgnoreCase = (ignoreCase == 1);
     retVal.IsContains = (SearchTypeIsContains)Int32.Parse(GetValue("IsContains", criterionText));
     retVal.TextTitle = (SearchTypeTextTitle)Int32.Parse(GetValue("TextTitle", criterionText));
     retVal.Where = (SearchTypeWhere)Int32.Parse(GetValue("Where", criterionText));
     retVal.Word = GetLastValue("Word",criterionText);
     return retVal;
 }
Пример #3
0
 public SearchCriterion GetSearchCriterion()
 {
     SearchCriterion retVal = new SearchCriterion();
     retVal.ConcatWithLast =  SearchTypeConcat.None;
     if (boxConcat.SelectedItem != null)
         retVal.ConcatWithLast = (SearchTypeConcat)SearchCriterionConverter.GetTextAsEnum(boxConcat.SelectedItem.ToString(), typeof(SearchTypeConcat));
     retVal.IsContains = (SearchTypeIsContains)SearchCriterionConverter.GetTextAsEnum(boxContainsIs.SelectedItem.ToString(), typeof(SearchTypeIsContains));
     retVal.Where = (SearchTypeWhere)SearchCriterionConverter.GetTextAsEnum(boxParentOrAncestor.SelectedItem.ToString(), typeof(SearchTypeWhere));
     retVal.TextTitle = (SearchTypeTextTitle)SearchCriterionConverter.GetTextAsEnum(boxTextOrTitle.SelectedItem.ToString(), typeof(SearchTypeTextTitle));
     retVal.Word = textBoxSearchText.Text;
     retVal.IgnoreCase = true;
     return retVal;
 }
Пример #4
0
 protected bool IsValid(SearchCriterion criterion)
 {
     return (criterion.Word != null && criterion.Word.Length > 0);
 }
Пример #5
0
        protected string GetShortDescription(SearchCriterion criterion)
        {
            System.Text.StringBuilder builder = new System.Text.StringBuilder(10);
            if (criterion.ConcatWithLast != SearchTypeConcat.None)
            {
                builder.Append(" ");
                builder.Append(criterion.ConcatWithLast);
                builder.Append(" ");
            }

            if (criterion.TextTitle == SearchTypeTextTitle.Id)
            {
                builder.Append("id=");
                builder.Append(criterion.Word);
            }
            else
            {
                builder.Append("\"");
                builder.Append(criterion.Word);
                builder.Append("\"");
            }
            return builder.ToString();
        }
Пример #6
0
        protected string GetDescription(SearchCriterion criterion)
        {
            System.Text.StringBuilder builder = new System.Text.StringBuilder(20);
            if (criterion.ConcatWithLast != SearchTypeConcat.None)
            {
                builder.Append("\n");
                builder.Append(criterion.ConcatWithLast);
                builder.Append("\n");
            }
            builder.Append("Snippets whose ");
            if (criterion.Where != SearchTypeWhere.Own)
            {
                builder.Append(criterion.Where.ToString().Replace("_"," "));
                if ((criterion.Where & SearchTypeWhere.Own) == 0)
                    builder.Append("'s");
                builder.Append(" ");
            }
            builder.Append(criterion.TextTitle.ToString().ToLower());
            if (criterion.TextTitle == SearchTypeTextTitle.Id)
            {
                try
                {
                    builder.Append("=");
                    builder.Append(criterion.Word);
                    string title = Universe.Instance.ModelGateway.FindSnippet(Int32.Parse(criterion.Word)).Title;
                    builder.Append(" (");
                    builder.Append(title);
                    builder.Append(")");
                }
                catch (Exception) {
                    // no problem, just hide this, snippet not found or id not numeric or
                    // whatever
                }

            } else {
                builder.Append(" ");
                builder.Append(criterion.IsContains.ToString().ToLower());
                builder.Append(" the text \"");
                builder.Append(criterion.Word);
                builder.Append("\"");
            }

            return builder.ToString();
        }
 public SerializableCriterion(SearchCriterion criterion)
 {
     makeText(criterion);
 }
 private void makeText(SearchCriterion criterion)
 {
     if (criterion.Word == null || criterion.Word.Length == 0)
         return;
     StringBuilder retVal = new StringBuilder();
     AppendNumber(retVal, "ConcatWithLast", (int)criterion.ConcatWithLast);
     int ignoreCase = 0;
     if (criterion.IgnoreCase)
         ignoreCase = 1;
     AppendNumber(retVal, "IgnoreCase", ignoreCase);
     AppendNumber(retVal, "IsContains", (int)criterion.IsContains);
     AppendNumber(retVal, "TextTitle", (int)criterion.TextTitle);
     AppendNumber(retVal, "Where", (int)criterion.Where);
     AppendText(retVal, "Word", criterion.Word);
     criterionText = retVal.ToString();
 }
Пример #9
0
        private bool ThisMatches(SearchCriterion criterion)
        {
            // we do not allow searching on the Search Snippet Parent
            if (this.IsSearchSnippetParent)
                return false;

            // We use the & for the ifs so that you can then add things, like
            // icon OR title contains

            // search the create
            if ((criterion.TextTitle & SearchTypeTextTitle.Created) > 0)
            {
                if (Matches(criterion.IsContains, criterion.Word, this.Created))
                    return true;
            }

            // search the create
            if ((criterion.TextTitle & SearchTypeTextTitle.Modified) > 0)
            {
                if (Matches(criterion.IsContains, criterion.Word, this.Modified))
                    return true;
            }

            // search the icon if necessary
            if ((criterion.TextTitle & SearchTypeTextTitle.Icon) > 0)
            {
                if (Matches(criterion.IsContains, criterion.Word, this.Icon, criterion.IgnoreCase))
                    return true;
            }

            // search the text if necessary
            if ((criterion.TextTitle & SearchTypeTextTitle.Text) > 0)
            {
                if (Matches(criterion.IsContains, criterion.Word, this.Text, criterion.IgnoreCase))
                    return true;
            }
            // search the title
            if ((criterion.TextTitle & SearchTypeTextTitle.Title) > 0)
            {
                if (Matches(criterion.IsContains, criterion.Word, this.Title, criterion.IgnoreCase))
                    return true;
            }
            // search the id
            if ((criterion.TextTitle & SearchTypeTextTitle.Id) > 0)
            {
                if (this.Id == Int32.Parse(criterion.Word))
                    return true;
            }
            return false;
        }
Пример #10
0
 private bool ParentMatches(SearchCriterion criterion)
 {
     bool continueToAncestors = ((criterion.Where & SearchTypeWhere.Ancestor) > 0);
     foreach (SnippetInMemory parent in Parents)
     {
         // it is okay to skip the search (and assume false) because it's already
         // been searched and these are ORs within one SearchCriterion
         if (parent.ThisMatches(criterion))
             return true;
         if (continueToAncestors)
         {
             if (parent.ParentMatches(criterion))
                 return true;
         }
     }
     return false;
 }
Пример #11
0
        public bool Matches(SearchCriterion criterion)
        {
            // where are we searching?
            // do we need to search the self?
            if ((criterion.Where & SearchTypeWhere.Own) > 0)
            {
                if (ThisMatches(criterion))
                    return true;
            }

            if ((criterion.Where & SearchTypeWhere.Parent) > 0 || (criterion.Where & SearchTypeWhere.Ancestor) > 0)
            {
                if (ParentMatches(criterion))
                    return true;
            }

            return false;
        }
Пример #12
0
        private bool ThisMatches(SearchCriterion criterion)
        {
            // search the icon if necessary
            if ((criterion.TextTitle & SearchTypeTextTitle.Icon) > 0)
            {
                if (Matches(criterion.IsContains, criterion.Word, this.Icon, criterion.IgnoreCase))
                    return true;
            }

            // search the text if necessary
            if ((criterion.TextTitle & SearchTypeTextTitle.Text) > 0)
            {
                if (Matches(criterion.IsContains, criterion.Word, this.Text, criterion.IgnoreCase))
                    return true;
            }
            // search the title
            if ((criterion.TextTitle & SearchTypeTextTitle.Title) > 0)
            {
                if (Matches(criterion.IsContains, criterion.Word, this.Title, criterion.IgnoreCase))
                    return true;
            }
            // search the id
            if ((criterion.TextTitle & SearchTypeTextTitle.Id) > 0)
            {
                if (this.Id == Int32.Parse(criterion.Word))
                    return true;
            }
            return false;
        }