public void MultipleDoubleDelimiterTest()
 {
     DnaStringParser parser = new DnaStringParser("blah1,, blah2,, blah3, ,, , ", delimiter, true, true, true);
     string[] substrings = parser.Parse();
     Assert.AreEqual(substrings.Length, 3, "Unexpected number of substrings.");
     Assert.AreEqual("blah1", substrings[0]);
     Assert.AreEqual("blah2", substrings[1]);
     Assert.AreEqual("blah3", substrings[2]);
 }
 public void BasicListTest()
 {
     Console.WriteLine("String Parser - BasicListTest");
     DnaStringParser parser = new DnaStringParser("blah1, blah2, blah3", delimiter,true,true,true);
     string[] substrings = parser.Parse();
     Assert.AreEqual(substrings.Length, 3, "Unexpected number of substrings."); 
     Assert.AreEqual("blah1", substrings[0]);
     Assert.AreEqual("blah2", substrings[1]);
     Assert.AreEqual("blah3", substrings[2]);
 }
 public void BasicGetParsedStringTest()
 {
     DnaStringParser parser = new DnaStringParser("blah1, blah2, blah3", delimiter, true, true, true);
     string commaSeparatedString = parser.GetParsedString(',');
     Assert.AreEqual("blah1,blah2,blah3,", commaSeparatedString); 
 }
 public void QuotedElementWithProblemCharactersTest()
 {
     string param = @"""blah1 &^%£$"", blah5, blah6,";
     DnaStringParser parser = new DnaStringParser(param, delimiter, true, true, true);
     string[] substrings = parser.Parse();
     Assert.AreEqual(substrings.Length, 3, "Unexpected number of substrings.");
     Assert.AreEqual("blah1 &^%£$", substrings[0]);
     Assert.AreEqual("blah5", substrings[1]);
     Assert.AreEqual("blah6", substrings[2]);
 }
 public void QuotedElementWithSpacesAndCommasTest()
 {
     string param = @"""blah1 blah2, blah3 blah4"", blah5, blah6,";
     DnaStringParser parser = new DnaStringParser(param, delimiter, true, true, true);
     string[] substrings = parser.Parse();
     Assert.AreEqual(substrings.Length, 3, "Unexpected number of substrings.");
     Assert.AreEqual("blah1 blah2 blah3 blah4", substrings[0]);
     Assert.AreEqual("blah5", substrings[1]);
     Assert.AreEqual("blah6", substrings[2]);
 }
Beispiel #6
0
        /// <summary>
        /// Generates an "AND" search query
        /// </summary>
        /// <param name="searchQuery">the original search query</param>
        /// <returns>the search term to pass into the stored proc</returns>
        private string GenerateANDSearchQuery(string searchQuery)
        {
            char[] delimiters = { ',', ' ' };
            DnaStringParser stringparser = new DnaStringParser(searchQuery, delimiters,true,true,false);
            string[] queries = stringparser.Parse();

            string search = string.Empty;
            for (int i = 0; i < queries.GetLength(0) - 1; i++)
            {
                search += "\"" + queries[i] + "\"" + " AND ";
            }

            search += "\"" + queries[queries.GetLength(0)-1] + "\"";

            return search;
        }
 public void TestParseToArrayWithSpaceDelimitedStringPreservingQuotesAndDelimetersAndDuplicates()
 {
     DnaStringParser parser = new DnaStringParser("search for \"phrase in quotes\" another other terms", new char[] { ' ' }, false, false, false);
     ArrayList strings = parser.ParseToArrayList();
     Assert.IsTrue(strings.Count == 6, "There should be five strings parsed!");
     Assert.AreEqual("search", strings[0]);
     Assert.AreEqual("for", strings[1]);
     Assert.AreEqual("\"phrase in quotes\"", strings[2]);
     Assert.AreEqual("another", strings[3]);
     Assert.AreEqual("other", strings[4]);
     Assert.AreEqual("terms", strings[5]);
 }
 public void CheckThatParseToArrayDoesNotRemoveDuplicatesWhenSpecified()
 {
     DnaStringParser parser = new DnaStringParser("blah5 \"blah1 blah2, blah3\"  blah5", new char[] { ' ' }, false, false, false);
     ArrayList strings = parser.ParseToArrayList();
     Assert.IsTrue(strings.Count == 3, "parsing the string with spaces should of only brought back 3 items!");
     Assert.AreEqual("blah5", strings[0], "The first string does not match expected value!");
     Assert.AreEqual("\"blah1 blah2, blah3\"", strings[1], "The second string does not match expected value!");
     Assert.AreEqual("blah5", strings[2], "The third string does not match expected value!");
 }
 public void DuplicateElementTest()
 {
     DnaStringParser parser = new DnaStringParser("blah1, blah2, blah3, blah3", delimiter, true, true, true);
     string[] substrings = parser.Parse();
     Assert.AreEqual(substrings.Length, 3, "Unexpected number of substrings.");
     Assert.AreEqual("blah1", substrings[0]);
     Assert.AreEqual("blah2", substrings[1]);
     Assert.AreEqual("blah3", substrings[2]);
 }
Beispiel #10
0
 public void MixedMultiplicityDelimiterTest()
 {
     DnaStringParser parser = new DnaStringParser("blah1, blah2,,, blah3,,,, blah4, blah5,,,, blah6, , blah7, ", delimiter, true, true, true);
     string[] substrings = parser.Parse();
     Assert.AreEqual(substrings.Length, 7, "Unexpected number of substrings.");
     Assert.AreEqual("blah1", substrings[0]);
     Assert.AreEqual("blah2", substrings[1]);
     Assert.AreEqual("blah3", substrings[2]);
     Assert.AreEqual("blah4", substrings[3]);
     Assert.AreEqual("blah5", substrings[4]);
     Assert.AreEqual("blah6", substrings[5]);
     Assert.AreEqual("blah7", substrings[6]);
 }
Beispiel #11
0
        /// <summary>
        /// Gets the params for the page
        /// </summary>
        /// <param name="asp">Class containing all the search parameters.</param>
        private bool TryGetPageParams(ref ArticleSearchParams asp)
        {
            int startDay = 0;
            int startMonth = 0;
            int startYear = 0;
            int endDay = 0;
            int endMonth = 0;
            int endYear = 0;

            string startDateText = String.Empty;
            string endDateText = String.Empty;

            //siteID = InputContext.GetParamIntOrZero("siteid", _docDnaSiteID);
            asp.SiteID = InputContext.CurrentSite.SiteID;

            int defaultShow = InputContext.GetSiteOptionValueInt("ArticleSearch", "DefaultShow");

            asp.Skip = InputContext.GetParamIntOrZero("skip", _docDnaSkip);
            asp.Show = InputContext.GetParamIntOrZero("show", _docDnaShow);
            if (asp.Show > 200)
            {
                asp.Show = 200;
            }
            else if (asp.Show < 1)
            {
                asp.Show = defaultShow;
            }

            asp.SkipPhrases = InputContext.GetParamIntOrZero("skipphrases", _docDnaSkipPhrases);
            asp.ShowPhrases = InputContext.GetParamIntOrZero("showphrases", _docDnaShowPhrases);
            if (asp.ShowPhrases > 200)
            {
                asp.ShowPhrases = 200;
            }
            else if (asp.ShowPhrases < 1)
            {
                asp.ShowPhrases = defaultShow;
            }
            if (asp.SkipPhrases < 1)
            {
                asp.SkipPhrases = 0;
            }

            asp.ContentType = InputContext.GetParamIntOrZero("contenttype", _docDnaContentType);
            asp.SortBy = InputContext.GetParamStringOrEmpty("articlesortby", _docDnaArticleSortBy);
            asp.DateSearchType = InputContext.GetParamIntOrZero("datesearchtype", _docDnaDateSearchType);

            asp.TimeInterval = InputContext.GetParamIntOrZero("timeinterval", _docDnaTimeInterval);

            startDay = InputContext.GetParamIntOrZero("startDay", _docDnaStartDay);
            startMonth = InputContext.GetParamIntOrZero("startMonth", _docDnaStartMonth);
            startYear = InputContext.GetParamIntOrZero("startYear", _docDnaStartYear);

            endDay = InputContext.GetParamIntOrZero("endDay", _docDnaEndDay);
            endMonth = InputContext.GetParamIntOrZero("endMonth", _docDnaEndMonth);
            endYear = InputContext.GetParamIntOrZero("endYear", _docDnaEndYear);

            startDateText = InputContext.GetParamStringOrEmpty("startDate", _docDnaStartDate);
            endDateText = InputContext.GetParamStringOrEmpty("endDate", _docDnaEndDate);

            asp.ArticleStatus = InputContext.GetParamIntOrZero("articlestatus", _docDnaArticleStatus);
            asp.ArticleType = InputContext.GetParamIntOrZero("articletype", _docDnaArticleType);

            int descendingOrderNum = InputContext.GetParamIntOrZero("descendingorder", _docDnaDescendingOrder);
            if (descendingOrderNum == 1)
            {
                asp.DescendingOrder = true;
            }
            else
            {
                asp.DescendingOrder = false;
            }

            DateTime startDate;
            DateTime endDate;

            if (asp.DateSearchType != 0)
            {
                DateRangeValidation dateValidation = new DateRangeValidation();
                DateRangeValidation.ValidationResult isValid;
                if (startDay == 0 && endDay == 0)
                {
                    isValid = ParseDateParams(startDateText, endDateText, out startDate, out endDate);
                }
                else
                {
                    isValid = ParseDateParams(startYear, startMonth, startDay, endYear, endMonth, endDay, out startDate, out endDate);
                }

                isValid = dateValidation.ValidateDateRange(startDate, endDate, asp.TimeInterval, false, false);

                if (isValid == DateRangeValidation.ValidationResult.VALID)
                {
                    asp.StartDate = dateValidation.LastStartDate;
                    asp.EndDate = dateValidation.LastEndDate;
                }
                else
                {
                    return AddErrorXml("invalidparameters", "Illegal date parameters (" + isValid.ToString() + ")", null);
                }
            }

            //Get Search phrases.
            if (InputContext.DoesParamExist("phrase", _docDnaPhrase))
            {
                asp.SearchPhraseList.Clear();

                string rawPhrases = String.Empty;
                for (int i = 0; i < InputContext.GetParamCountOrZero("phrase", _docDnaPhrase); i++)
                {
                    string phrase = InputContext.GetParamStringOrEmpty("phrase", i, _docDnaPhrase);
                    if (phrase.Contains(_token))
                    {
                        DnaStringParser paramParser = new DnaStringParser(phrase, _token.ToCharArray(), false, false, false);
                        ArrayList paramPhraseList = paramParser.ParseToArrayList();
                        foreach (string paramPhrase in paramPhraseList)
                        {
                            rawPhrases = rawPhrases + paramPhrase + "|";
                        }
                    }
                    else
                    {
                        rawPhrases = rawPhrases + phrase + "|";
                    }
                }

                string rawNameSpaces = String.Empty;
                for (int i = 0; i < InputContext.GetParamCountOrZero("namespace", _docDnaNameSpace); i++)
                {
                    string nameSpace = InputContext.GetParamStringOrEmpty("namespace", i, _docDnaNameSpace);
                    if (nameSpace.Contains(_token))
                    {
                        DnaStringParser paramParser = new DnaStringParser(nameSpace, _token.ToCharArray(), false, false, false);
                        ArrayList paramNameList = paramParser.ParseToArrayList();
                        foreach (string paramNameSpace in paramNameList)
                        {
                            rawNameSpaces = rawNameSpaces + paramNameSpace + "|";
                        }
                    }
                    else
                    {
                        rawNameSpaces = rawNameSpaces + nameSpace + "|";
                    }
                }

                char[] charsToTrim = new char[] { '|' };

                string parsedPhrases = String.Empty;
                //Now feed it into the DnaString Parser
                DnaStringParser phrasesParser = new DnaStringParser(rawPhrases, charsToTrim, true, true, false);
                parsedPhrases = phrasesParser.GetParsedString('|');
                ArrayList searchPhraseList = phrasesParser.ParseToArrayList();

                string parsedNameSpaces = String.Empty;
                //Now feed it into the DnaString Parser
                DnaStringParser nameSpaceParser = new DnaStringParser(rawNameSpaces, charsToTrim, true, true, false);
                parsedNameSpaces = nameSpaceParser.GetParsedString('|');
                ArrayList searchNameSpaceList = nameSpaceParser.ParseToArrayList();

                int phraseNumber = 0;
                foreach (string phraseText in searchPhraseList)
                {
                    Phrase phrase = new Phrase();
                    phrase.PhraseName = phraseText;
                    try
                    {
                        phrase.NameSpace = searchNameSpaceList[phraseNumber].ToString();
                    }
                    catch (ArgumentOutOfRangeException)
                    {
                        phrase.NameSpace = "";
                    }

                    asp.SearchPhraseList.Add(phrase);
                    phraseNumber++;
                }

                asp.Phrases = parsedPhrases.TrimEnd(charsToTrim);
                asp.NameSpaces = parsedNameSpaces.TrimEnd(charsToTrim);
            }

            //Get (Postcode or Placename or Latitude and Longitude) and Range for Search if they are there.
            if (InputContext.DoesParamExist("postcode", _docDnaPostcode) ||
                InputContext.DoesParamExist("placename", _docDnaPlacename) ||
                (InputContext.DoesParamExist("latitude", _docDnaLatitude) &&
                InputContext.DoesParamExist("longitude", _docDnaLongitude)) &&
                InputContext.DoesParamExist("range", _docDnaRange))
            {
                asp.Range = InputContext.GetParamDoubleOrZero("range", _docDnaRange);

                asp.LocationSearchType = InputContext.GetParamStringOrEmpty("locationsearchtype", _docDnaLocationSearchType);
                asp.PostCode = InputContext.GetParamStringOrEmpty("postcode", _docDnaPostcode);
                asp.Placename = InputContext.GetParamStringOrEmpty("placename", _docDnaPlacename);

                double latitude = InputContext.GetParamDoubleOrZero("latitude", _docDnaLatitude); 
                double longitude = InputContext.GetParamDoubleOrZero("longitude", _docDnaLongitude);
                if (asp.LocationSearchType == "postcode")
                {
                    GetLatLongFromPostCode(asp.PostCode, ref latitude, ref longitude);
                }
                else if (asp.LocationSearchType == "placename")
                {
                    GetLatLongFromPlacename(asp.Placename, ref latitude, ref longitude);
                }
                asp.Latitude = latitude;
                asp.Longitude = longitude;
            }

            //Get free text search condition for Search if it is there.
            if (InputContext.DoesParamExist("freetextsearch", _docDnaFreeTextSearchCondition))
            {
                asp.FreeTextSearchCondition = InputContext.GetParamStringOrEmpty("freetextsearch", _docDnaFreeTextSearchCondition);
            }

            return true;
        }
Beispiel #12
0
        /// <summary>
        /// Get one of multiple named parameters
        /// </summary>
        /// <param name="paramName">Name of parameter</param>
        /// <param name="index">index of parameter</param>
        /// <param name="description">description of parameter</param>
        /// <returns>bool value of parameter</returns>
        public bool GetParamBoolOrFalse(string paramName, int index, string description)
        {
            if (_request[paramName] != null)
            {
                DnaStringParser parser = new DnaStringParser(_request[paramName], new char[] { ',' }, true, false, false);
                ArrayList paramnames = parser.ParseToArrayList();
                if (paramnames.Count > index)
                {
                    bool paramValue = false;
                    bool.TryParse(paramnames[index].ToString(), out paramValue);

                    paramValue = paramValue || paramnames[index].ToString() == "1";
                    
                    return paramValue;
                }
            }
            return false;
        }
Beispiel #13
0
 /// <summary>
 /// Get one of multiple named parameters
 /// </summary>
 /// <param name="paramName">Name of parameter</param>
 /// <param name="index">index of parameter</param>
 /// <param name="description">description of parameter</param>
 /// <returns>value of parameter</returns>
 public int GetParamIntOrZero(string paramName, int index, string description)
 {
     if (_request[paramName] != null)
     {
         DnaStringParser parser = new DnaStringParser(_request[paramName], new char[] { ',' }, true, false, false);
         ArrayList paramnames = parser.ParseToArrayList();
         if (paramnames.Count > index)
         {
             int paramValue = 0;
             Int32.TryParse(paramnames[index].ToString(), out paramValue);
             return paramValue;
         }
     }
     return 0;
 }
Beispiel #14
0
        /// <summary>
        /// Generates an "AND" search query
        /// </summary>
        /// <param name="searchQuery">the original search query</param>
        /// <returns>the search term to pass into the stored proc</returns>
        public static string GenerateANDSearchQuery(string searchQuery)
        {
            char[] delimiters = { ',', ' ' };
            DnaStringParser stringparser = new DnaStringParser(searchQuery, delimiters, true, true, false);
            string[] queries = stringparser.Parse();

            return SearchThreadPosts.FormatSearchTerm(ref queries);
        }
Beispiel #15
0
 public void GetParsedStringWithDoubleDelimitersAndQuotesTest()
 {
     DnaStringParser parser = new DnaStringParser("\"blah1 blah2, blah3\",, blah4, blah5,,,", delimiter, true, true, true);
     string commaSeparatedString = parser.GetParsedString(',');
     Assert.AreEqual("blah1 blah2 blah3,blah4,blah5,", commaSeparatedString);
 }
Beispiel #16
0
 public void GetParsedStringUsingPipesAsDelimitersWithSpacesAndQuotesTest()
 {
     char[] pipe = new char[] { '|' };
     DnaStringParser parser = new DnaStringParser("\"blah1 blah2, blah3\"| blah4| blah5|||", pipe, true, true, true);
     string commaSeparatedString = parser.GetParsedString('|');
     Assert.AreEqual("blah1 blah2, blah3|blah4|blah5|", commaSeparatedString);
 }
Beispiel #17
0
 public void DuplicateElementCaseWithDoubleDelimitersTest()
 {
     DnaStringParser parser = new DnaStringParser("blah1, blah2,, blah3, blah3, , , , ,, BLAH3,, bLah2", delimiter, true, true, true);
     string[] substrings = parser.Parse();
     Assert.AreEqual(substrings.Length, 5, "Unexpected number of substrings.");
     Assert.AreEqual("blah1", substrings[0]);
     Assert.AreEqual("blah2", substrings[1]);
     Assert.AreEqual("blah3", substrings[2]);
     Assert.AreEqual("BLAH3", substrings[3]);
     Assert.AreEqual("bLah2", substrings[4]);
 }
Beispiel #18
0
 public void TestParseToArrayRemovesQuotesAndDelimitersButNotDuplicates()
 {
     DnaStringParser parser = new DnaStringParser("blah1, \"blah,blah\", blah1", new char[] { ',' }, true, true, false);
     ArrayList strings = parser.ParseToArrayList();
     Assert.IsTrue(strings.Count == 3, "There should be two strings parsed!");
     Assert.AreEqual("blah1", strings[0]);
     Assert.AreEqual("blahblah", strings[1]);
     Assert.AreEqual("blah1", strings[2]);
 }
Beispiel #19
0
 public void MultipleQuotedElementsTest()
 {
     string param = @"""blah1"", ""blah2""";
     DnaStringParser parser = new DnaStringParser(param, delimiter, true, true, true);
     string[] substrings = parser.Parse();
     Assert.AreEqual(substrings.Length, 2, "Unexpected number of substrings.");
     Assert.AreEqual("blah1", substrings[0]);
     Assert.AreEqual("blah2", substrings[1]);
 }
Beispiel #20
0
 public void QuotedNonQuotedElementMixTest()
 {
     string param = @"""blah1"", blah2, blah3, ""blah4""";
     DnaStringParser parser = new DnaStringParser(param, delimiter, true, true, true);
     string[] substrings = parser.Parse();
     Assert.AreEqual(substrings.Length, 4, "Unexpected number of substrings.");
     Assert.AreEqual("blah1", substrings[0]);
     Assert.AreEqual("blah2", substrings[1]);
     Assert.AreEqual("blah3", substrings[2]);
     Assert.AreEqual("blah4", substrings[3]);
 }
Beispiel #21
0
        /// <summary>
        /// Generates the SQL Search Query.
        /// </summary>
        /// <param name="searchQuery"></param>
        /// <returns></returns>
        private string GenerateSearchQuery(string searchQuery)
        {
            char[] delimiters = { ',', ' ' };
            DnaStringParser stringparser = new DnaStringParser(searchQuery, delimiters,true,true,false);
            string[] queries = stringparser.Parse();

            string search = "isabout(";
            string comma = " ";
            foreach (string query in queries)
            {
                search += comma + query + " weight (0.5)";
                comma = ",";
            }

            foreach (string query in queries)
            {
                search += comma + "formsof(inflectional, " + query + ") weight(0.25)";
                comma = ",";
            }

            search += comma + "\"" + searchQuery + "\"" + " weight(1.0)";
            search += ")";

            return search;
        }