Ejemplo n.º 1
0
    // the default bookInfos that greet a user at the beginning
    public List<WhirlwindBeltInfo> GetDefaultBookInfos(int numBelts)
    {
        if (connectionSuccess) {
            List<WhirlwindBeltInfo> retVal = new List<WhirlwindBeltInfo>();

            // query everything, do not include the ones that we have no images for
            List<BookInfo> results = connector.Search("", columns[0]);
            for (int i = 0; i < results.Count; i++) {
                if (!WhirlwindItem.HasItemSprite(results[i].FileName)) {
                    results.Remove(results[i]);
                }
            }

            List<BookInfo> b;
            WhirlwindBeltInfo wwbi;

            int amountPerBelt;
            int prevBeltEndIndex = 0;
            // take chunks out (based on belt sizes) of all the entries so nothing repeats
            for (int i = 0; i < columns.Length; i++) {
                amountPerBelt = 4 + i * 3;
         				b = results.GetRange(prevBeltEndIndex, amountPerBelt);
                wwbi = new WhirlwindBeltInfo(b, columnTitles[i]);
                retVal.Add(wwbi);
                prevBeltEndIndex += amountPerBelt + 1;
            }

            // sort the search results by popularity
            retVal.Sort(delegate(WhirlwindBeltInfo b1, WhirlwindBeltInfo b2) { return b2.InfosCount.CompareTo(b1.InfosCount); });

            // return the top N results (pad if necessary)
            retVal = retVal.GetRange(0, numBelts);
            return retVal;
        } else {
            return OfflinePlaceHolderSearch(numBelts);
        }
    }
Ejemplo n.º 2
0
    /////// public functions used for manipulating data //////
    public void LoadNewItems(WhirlwindBeltInfo infos)
    {
        GameObject g;

        beltEnd.Enable(false);

        // wipe old items away
        for (int i = 0; i < wwItems.Count; i++) {
            wwItems[i].SlatedToBeDestroyed();
        }

        // instantiate new items
        wwItems = new List<WhirlwindItem>();
        for (int i = 0; i < infos.Infos.Count; i++) {
            g = (GameObject)MonoBehaviour.Instantiate(Resources.Load("Prefabs/WhirlwindItem"));
            WhirlwindItem wwi = g.GetComponent<WhirlwindItem>();
            wwi.Initialize(this, radius, defaultItemPosition, infos.Infos[i]);
            wwItems.Add(wwi);
        }
        // set the label
        label.Text = infos.Label;
    }
Ejemplo n.º 3
0
    // search via the search bar and "explore" button
    public List<WhirlwindBeltInfo> Search(List<BookInfo> inputInfos, int numBelts)
    {
        Debug.Assert(inputInfos != null && inputInfos.Count > 0);

        if (connectionSuccess) {
            List<WhirlwindBeltInfo> retVal = new List<WhirlwindBeltInfo>();

            List<BookInfo> b;
            WhirlwindBeltInfo wwbi;

            // search through the columns
            for (int i = 0; i < columns.Length; i++) {

                // aggregate the terms of which we search
                List<string> searchTerms = new List<string>();
                for (int j = 0; j < inputInfos.Count; j++) {
                    if (columns[i].Equals("subject")) {
                        searchTerms.AddRange(inputInfos[j].GetSubjects());
                    } else {
                        searchTerms.Add(inputInfos[j].GetData(columns[i]));
                    }
                }

                // make a query
                if (columns[i].Equals("subject")) {
                    b = connector.SearchBySubject(searchTerms);
                } else {
                    b = connector.Search(searchTerms, columns[i]);
                }

         				// remove ones that are the same as the search terms
         				for (int j = 0; j < b.Count; j++) {
         					for (int k = 0; k < inputInfos.Count; k++) {
         						if (b[j].FileName.Equals(inputInfos[k].FileName)) {
         						b.Remove(b[j]);
         						j--;
         						break;
         					}
         					}
         				}

         				// limits the items count
                b = b.GetRange(0, Mathf.Min(b.Count, maxItemsPerBelt));
                wwbi = new WhirlwindBeltInfo(b, columnTitles[i]);
                retVal.Add(wwbi);
            }

            // sort the search results by popularity
            retVal.Sort(delegate(WhirlwindBeltInfo b1, WhirlwindBeltInfo b2) { return b2.InfosCount.CompareTo(b1.InfosCount); });

            // return the top N results (pad if necessary)
            retVal = retVal.GetRange(0, numBelts);
            return retVal;
        } else {
            return OfflinePlaceHolderSearch(numBelts);
        }
    }