WEB前端

尚硅谷电商推荐系统前端代码

//统计的表的名称

val RATE_MORE_PRODUCTS = “RateMoreProducts”

val RATE_MORE_RECENTLY_PRODUCTS = “RateMoreRecentlyProducts”

尚硅谷电商推荐系统前端代码

val AVERAGE_PRODUCTS = “AverageProducts”

// 入口方法

def main(args: Array[String]): Unit = {

val config = Map(

“spark.cores” – “local[*]”,

“mongo.uri” – “mongodb://localhost:27017/recommender”,

“mongo.db” – “recommender”

//创建SparkConf配置

val sparkConf = new SparkConf().setAppName(“StatisticsRecommender”).setMaster(config(“spark.cores”))

//创建SparkSession

val spark = SparkSession.builder().config(sparkConf).getOrCreate()

val mongoConfig = MongoConfig(config(“mongo.uri”),config(“mongo.db”))

//加入隐式转换

import spark.implicits._

//数据加载进来

val ratingDF = spark

.read

.option(“uri”,mongoConfig.uri)

.option(“collection”,MONGODB_RATING_COLLECTION)

.format(“com.mongodb.spark.sql”)

.load()

.as[Rating]

.toDF()

//创建一张名叫ratings的表

ratingDF.createOrReplaceTempView(“ratings”)

//TODO: 不同的统计推荐结果

spark.stop()

Similar Posts

发表评论

邮箱地址不会被公开。 必填项已用*标注