Solr之.net操作

 http://www.cnblogs.com/zhangweizhong/category/771055.html

            插入:
            SolrNet.Startup.Init<Movie>("http://127.0.0.1:8983/solr/movies");
            ISolrOperations<Movie> solr = ServiceLocator.Current.GetInstance<ISolrOperations<Movie>>();
            Movie movie = new Movie();
            movie.Id = "888888888888";
            movie.Content = "王宝强三打马蓉";
            movie.Ed2k = "ed2k://";
            movie.Title = "王宝强三打马蓉";
            solr.Add(movie);
            solr.Commit();

            //搜索:
            SolrNet.Startup.Init<Movie>("http://127.0.0.1:8983/solr/movies");
            ISolrOperations<Movie> solr = ServiceLocator.Current.GetInstance<ISolrOperations<Movie>>();

            QueryOptions option = new QueryOptions();
            option.AddOrder(new SolrNet.SortOrder("id", Order.DESC));
            option.StartOrCursor = new SolrNet.StartOrCursor.Start(0);
            option.Rows = 10;
            SolrQuery query = new SolrQuery("title:\"王宝强\"");
            SolrQueryResults<Movie> results = solr.Query(query, option);
            Console.WriteLine("总条数:" + results.NumFound);
            for (int i = 0; i < results.Count; i++)
            {
                Movie movie = results[i];
                Console.WriteLine(movie.Title);
            }

  

posted @ 2016-09-15 11:24  ~沐风  阅读(274)  评论(0编辑  收藏  举报