Exemple #1
0
        /// <summary>
        /// Within a set of terms, contains a starts with in a given position.
        /// </summary>
        /// <param name="terms">The set of terms.</param>
        /// <param name="searchText">The search text.</param>
        /// <param name="position">The desired position of the match within the terms.</param>
        /// <returns>Whether a match was found within the terms.</returns>
        public static bool ContainsStartsWithInPosition(string[] terms, string searchText, int position)
        {
            bool containsStartsWithInPosition = false;

            foreach (string text in terms)
            {
                string[] textParts = text.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if (textParts.Length > position && DrugSearchHelper.StartsWith(textParts[position], searchText))
                {
                    containsStartsWithInPosition = true;
                }
            }

            return(containsStartsWithInPosition);
        }
Exemple #2
0
        /// <summary>
        /// Gets matches from a list of drugs containing a StartsWith match where the match is in a specific position, in a specific ingredient position.
        /// </summary>
        /// <param name="matchPosition">The desired position of the match.</param>
        /// <param name="ingredientPosition">The desired position of the ingredient.</param>
        /// <param name="searchText">The search text.</param>
        /// <param name="drugs">The drugs to search.</param>
        /// <param name="ignoreDrugs">The drugs to ignore.</param>
        /// <param name="hasGeneric">Whether drugs with generics are included.</param>
        /// <param name="hasBrand">Whether drugs with a brand are included.</param>
        /// <returns>An array of matches.</returns>
        private static Drug[] GetMatches(int matchPosition, int ingredientPosition, string searchText, Drug[] drugs, Drug[] ignoreDrugs, bool hasGeneric, bool hasBrand)
        {
            Drug[] matches = (from drug in drugs
                              where !ignoreDrugs.Contains(drug) &&
                              ((hasGeneric && !hasBrand) ? string.IsNullOrEmpty(drug.BrandName) && !string.IsNullOrEmpty(drug.Name) && (drug.Name.Split("+".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length > ingredientPosition && drug.Name.Split("+".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[ingredientPosition].Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length > matchPosition && DrugSearchHelper.StartsWith(drug.Name.Split("+".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[ingredientPosition].Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[matchPosition], searchText)) :
                               (hasGeneric && hasBrand) ? !string.IsNullOrEmpty(drug.BrandName) && !string.IsNullOrEmpty(drug.Name) && (drug.BrandName.Split("+".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length > ingredientPosition && drug.BrandName.Split("+".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[ingredientPosition].Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length > matchPosition && DrugSearchHelper.StartsWith(drug.BrandName.Split("+".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[ingredientPosition].Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[matchPosition], searchText)) :
                               (!hasGeneric && hasBrand) ? !string.IsNullOrEmpty(drug.BrandName) && string.IsNullOrEmpty(drug.Name) && (drug.BrandName.Split("+".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length > ingredientPosition && drug.BrandName.Split("+".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[ingredientPosition].Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length > matchPosition && DrugSearchHelper.StartsWith(drug.BrandName.Split("+".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[ingredientPosition].Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[matchPosition], searchText)) :
                               false)
                              select drug).OrderBy(a => (!hasBrand) ? a.Name != null ? a.Name.Replace("-", "0") : a.Name : a.BrandName != null ? a.BrandName.Replace("-", "0") : a.BrandName).ThenBy(a => a.Name != null ? a.Name.Replace("-", "0") : a.Name).ToArray();

            return(matches);
        }