Exemple #1
0
 public void TestAddItem()
 {
     CatalogItem item = new CatalogItem();
     item.Name = "Test";
     _catalog.Add(item);
     Assert.IsTrue(_catalog.Contains(item));
 }
Exemple #2
0
        private uint Match(CatalogItem item, string term)
        {
            uint retVal = 0;

            string lname = item.Name.ToLower();
            string lterm = term.ToLower();

            if (lname == lterm)
                retVal += 1000;

            if (lname.IndexOf(lterm) != -1)
                retVal += 100;

            if(item.CountPerWord.ContainsKey(lterm)) retVal += item.CountPerWord[term] * 10;

            int last = 0;
            for (int i = 0; i < lterm.Length; i++)
            {
                int idx = lname.IndexOf(lterm[i], last);
                if (idx != -1)
                {
                    if (idx == 0 || lname[idx - 1] == ' ')
                    {
                        retVal += 40;
                    }
                    else
                    {
                        retVal += 20;
                    }
                    last = idx;
                }
                else if (retVal >= 5)
                {
                    retVal -= 5;
                }
            }
            if (retVal > lname.Length / 2) retVal -= (uint)lname.Length / 2;

            item.Score = retVal;
            return retVal;
        }