Ejemplo n.º 1
0
        private void Initialize()
        {
            //See if there are movies in the solr dataset
            bool hasRecords = _solr.Query(new SolrQuery("*:*"), new QueryOptions()
            {
                Rows = 10
            }).Count > 0;

            if (hasRecords)
            {
                return;
            }

            //Populate the dataset with the csv data
            List <Movie> movies;
            string       filepath = Path.Combine(_appBasePath, "data", "movies_metadata.csv");

            //Load csv, add movies
            using (StreamReader reader = new StreamReader(filepath))
                using (CsvReader csv = new CsvReader(reader))
                {
                    csv.Configuration.RegisterClassMap <MovieCsvMapper>();
                    csv.Configuration.MissingFieldFound = null;
                    movies = csv.GetRecords <Movie>().ToList();
                }

            //Send to solr
            ResponseHeader addResult        = _solr.AddRange(movies);
            ResponseHeader commitResult     = _solr.Commit();
            ResponseHeader spellCheckResult = _solr.BuildSpellCheckDictionary();

            //Something went wrong
            if (addResult.Status != 0)
            {
                HandleError(addResult, "add");
            }

            if (commitResult.Status != 0)
            {
                HandleError(commitResult, "commit");
            }

            if (spellCheckResult.Status != 0)
            {
                HandleError(spellCheckResult, "build spellcheck library");
            }
        }