Exemple #1
0
        // TODO :
        // word, number and phrase terms are currently only compared against database field 'Title'.
        // they should probably compared to other common database fields as well.
        // but this would slow down searching a lot..
        // maybe some smarter table indexers settings would help.
        internal override void OnTermParsed(TermParsedEventArgs e, out ISearchCriteria criteria)
        {
            criteria = null;

            switch (e.TermType) {
                case TermType.Number:
                    criteria = new FreeTextSearchCriteria(e.Number.ToString(),
                                                      FreeTextSearchField.Title,
                                                      TextCompareOperator.Contains);
                    break;
                case TermType.Phrase:
                    criteria = new FreeTextSearchCriteria(e.Phrase,
                                                      FreeTextSearchField.Title,
                                                      TextCompareOperator.Contains);
                    break;
                case TermType.Word:
                    criteria = new FreeTextSearchCriteria(e.Word,
                                                      FreeTextSearchField.Title,
                                                      TextCompareOperator.Contains);
                    break;
                case TermType.Select:

                    string keyword = e.Keyword.ToUpper();

                    // try to map the keyword to a volumes quantity field
                    if (quantityFields.ContainsKey(keyword)) {

                        long byteSize = e.Number;
                        if (byteSize == -1L) {
                            try {
                                byteSize = GetByteSize(e.Word);
                            } catch (ArgumentException) {
                                throw new ArgumentException(
                                    string.Format(S._("Operand for keyword '{0}' must be a number with an optional multiplier"), e.Keyword),
                                    "euslQuery");
                            }
                        }

                        CompareOperator cOp = CompareOperator.Equal;
                        try {
                            cOp = GetNumericCompareOpForRelation(e.Relation);
                        } catch (ArgumentException) {
                            throw new ArgumentException(
                                                    string.Format(S._("Invalid compare operator for keyword '{0}'"), e.Keyword),
                                                    "euslQuery");
                        }

                        criteria = new QuantitySearchCriteria(quantityFields[keyword], byteSize, cOp);

                    } else {
                        // try to map the keyword to freetextsearch fields

                        IFreeTextSearchField sf;

                        try {
                            sf = FreeTextSearchField.FromString(e.Keyword);
                        } catch (ArgumentException) {
                            throw new ArgumentException(
                                        string.Format(S._("Unknown keyword '{0}'"), e.Keyword),
                                        "euslQuery");
                        }

                        TextCompareOperator tcOp = TextCompareOperator.Contains;

                        try {
                            tcOp = GetTextCompareOpForRelation(e.Relation);
                        } catch (ArgumentException) {
                            throw new ArgumentException(
                                                    S._("Invalid compare operator for a keyword that maps to textual content"),
                                                    "euslQuery");
                        }

                        string s;
                        if (e.Number != -1L)
                            s = e.Number.ToString();
                        else if (e.Word != null)
                            s = e.Word;
                        else
                            s = e.Phrase;

                        // throws argument exception if searchstr is too short
                        criteria = new FreeTextSearchCriteria(s, sf, tcOp);
                    }
                    break;
            }

            if (e.ExcludeTerm)
                criteria = new ExcludedSearchCriteria(criteria);
        }
Exemple #2
0
        // TODO :
        // word, number and phrase terms are currently only compared against database field 'Title'.
        // they should probably compared to other common database fields as well.
        // but this would slow down searching a lot..
        // maybe some smarter table indexers settings would help.
        internal override void OnTermParsed(TermParsedEventArgs e, out ISearchCriteria criteria)
        {
            criteria = null;

            switch (e.TermType)
            {
            case TermType.Number:
                criteria = new FreeTextSearchCriteria(e.Number.ToString(),
                                                      FreeTextSearchField.Title,
                                                      TextCompareOperator.Contains);
                break;

            case TermType.Phrase:
                criteria = new FreeTextSearchCriteria(e.Phrase,
                                                      FreeTextSearchField.Title,
                                                      TextCompareOperator.Contains);
                break;

            case TermType.Word:
                criteria = new FreeTextSearchCriteria(e.Word,
                                                      FreeTextSearchField.Title,
                                                      TextCompareOperator.Contains);
                break;

            case TermType.Select:

                string keyword = e.Keyword.ToUpper();

                // try to map the keyword to a volumes quantity field
                if (quantityFields.ContainsKey(keyword))
                {
                    long byteSize = e.Number;
                    if (byteSize == -1L)
                    {
                        try {
                            byteSize = GetByteSize(e.Word);
                        } catch (ArgumentException) {
                            throw new ArgumentException(
                                      string.Format(S._("Operand for keyword '{0}' must be a number with an optional multiplier"), e.Keyword),
                                      "euslQuery");
                        }
                    }

                    CompareOperator cOp = CompareOperator.Equal;
                    try {
                        cOp = GetNumericCompareOpForRelation(e.Relation);
                    } catch (ArgumentException) {
                        throw new ArgumentException(
                                  string.Format(S._("Invalid compare operator for keyword '{0}'"), e.Keyword),
                                  "euslQuery");
                    }

                    criteria = new QuantitySearchCriteria(quantityFields[keyword], byteSize, cOp);
                }
                else
                {
                    // try to map the keyword to freetextsearch fields

                    IFreeTextSearchField sf;

                    try {
                        sf = FreeTextSearchField.FromString(e.Keyword);
                    } catch (ArgumentException) {
                        throw new ArgumentException(
                                  string.Format(S._("Unknown keyword '{0}'"), e.Keyword),
                                  "euslQuery");
                    }

                    TextCompareOperator tcOp = TextCompareOperator.Contains;

                    try {
                        tcOp = GetTextCompareOpForRelation(e.Relation);
                    } catch (ArgumentException) {
                        throw new ArgumentException(
                                  S._("Invalid compare operator for a keyword that maps to textual content"),
                                  "euslQuery");
                    }

                    string s;
                    if (e.Number != -1L)
                    {
                        s = e.Number.ToString();
                    }
                    else if (e.Word != null)
                    {
                        s = e.Word;
                    }
                    else
                    {
                        s = e.Phrase;
                    }

                    // throws argument exception if searchstr is too short
                    criteria = new FreeTextSearchCriteria(s, sf, tcOp);
                }
                break;
            }

            if (e.ExcludeTerm)
            {
                criteria = new ExcludedSearchCriteria(criteria);
            }
        }