GetMoviesById() public method

Return the movies by its id
public GetMoviesById ( IEnumerable ids ) : MovieEntity>.IDictionary
ids IEnumerable
return MovieEntity>.IDictionary
示例#1
0
        public void IndexSelectedMovies(ISet<string> movieIds)
        {
            StandardAnalyzer analyzer = null;
            IndexWriter writer = null;
            try
            {
                analyzer = new StandardAnalyzer(Version.LUCENE_30);
                writer = new IndexWriter(_dirLocation, analyzer,
                                             IndexWriter.MaxFieldLength.UNLIMITED);

                var tableManager = new TableManager();

                var movieList = tableManager.GetMoviesById(GenerateListFromSet(movieIds));

                foreach (var id in movieIds)
                {
                    if (movieList.ContainsKey(id))
                    {
                        Trace.TraceInformation("Adding {0} to the index", id);

                        var movieEntity = movieList[id];

                        // delete entry if exists
                        var searchQuery = new TermQuery(new Term(Constants.Constants.Field_Id, id));
                        writer.DeleteDocuments(searchQuery);

                        // add to index again
                        var doc = new Document();
                        doc.Add(new Field(Constants.Constants.Field_Id, movieEntity.MovieId, Field.Store.YES,
                                          Field.Index.NOT_ANALYZED));
                        doc.Add(new Field(Constants.Constants.Field_Name, movieEntity.Name, Field.Store.YES,
                                          Field.Index.NOT_ANALYZED));
                        doc.Add(new Field(Constants.Constants.Field_AltNames, movieEntity.AltNames, Field.Store.NO, Field.Index.ANALYZED));

                        doc.Add(new Field(Constants.Constants.Field_Actors, movieEntity.Posters, Field.Store.NO,
                                          Field.Index.ANALYZED));
                        doc.Add(new Field(Constants.Constants.Field_Directors, movieEntity.Rating, Field.Store.YES,
                                          Field.Index.ANALYZED));
                        doc.Add(new Field(Constants.Constants.Field_MusicDirectors, movieEntity.Cast,
                                          Field.Store.YES, Field.Index.ANALYZED));
                        doc.Add(new Field(Constants.Constants.Field_Name, movieEntity.Name, Field.Store.YES,
                                          Field.Index.ANALYZED));
                        doc.Add(new Field(Constants.Constants.Field_Producers, movieEntity.Synopsis, Field.Store.YES,
                                          Field.Index.ANALYZED));
                        doc.Add(new Field(Constants.Constants.Field_MovieSynopsis, movieEntity.Synopsis, Field.Store.YES,
                                          Field.Index.ANALYZED));

                        writer.AddDocument(doc);
                    }
                    else
                    {
                        Trace.TraceWarning("movie {0} not present in db", id);
                    }
                }

            }
            catch (Exception err)
            {
                Trace.TraceError("Failed to build index {0}", err);

            }
            finally
            {
                if (analyzer != null)
                    analyzer.Close();
                if (writer != null)
                    writer.Dispose();
            }
        }