Skip to content

Commit

Permalink
MOD:支持加载其他目录索引
Browse files Browse the repository at this point in the history
  • Loading branch information
leosam1024 committed Jun 25, 2023
1 parent e53fbb9 commit 6a214d9
Show file tree
Hide file tree
Showing 12 changed files with 372 additions and 92 deletions.
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ mv视频搜索服务

# 请求接口

## Vod搜索接口
## MV视频Vod搜索接口
http://localhost:7777/mv/vod?maxCount=100&wd=五月天后来的我们

该接口只请求MV视频

请求参数定义
~~~
wd :搜索值,mv名称或者歌手名 都可以
Expand All @@ -31,8 +33,34 @@ maxCount:最大返回值,返回结果里面 list 最大数量。 最大值10
}
~~~

## 自定义数据源-Vod搜索接口
http://localhost:7777/vod/:index?maxCount=100&wd=五月天后来的我们

### 使用方法
1.`jar`所在文件目录下创建`data`文件夹
2. 将自定义数据源文件放入`data`文件夹下
3. 自定义数据源名称为数据源文件名,如`dome.json`,则数据源名称为`dome`
4. 自定义数据源文件格式如下: `视频名称,视频链接`
4. 请求接口`http://localhost:7777/vod/dome?maxCount=100&wd=五月天后来的我们`

请求路径参数定义
~~~
:index :数据源名称,如:dome,不带文件后缀
~~~

请求参数定义
~~~
wd :搜索值,mv名称或者歌手名 都可以
ids :vodId,同wd
maxCount:最大返回值,返回结果里面 list 最大数量。 最大值1000
~~~
返回参数结果
~~~
同上
~~~


## 搜素接口
## MV视频搜素接口
http://localhost:7777/mv/search?maxCount=100&query=五月天后来的我们

请求参数定义
Expand Down Expand Up @@ -81,6 +109,14 @@ maxCount:最大返回值,返回结果里面 list 最大数量。 最大值10
"searchable": 1,
"quickSearch": 1,
"filterable": 1
}, {
"key": "MV_vod_DOME",
"name": "👀┃DOME┃视频",
"type": 1,
"api": "http://你自己域名:7777/dome",
"searchable": 1,
"quickSearch": 1,
"filterable": 1
}
]
~~~
Expand Down
24 changes: 24 additions & 0 deletions data/dome.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
水陆古法养鱼池塘缸,保姆级教程,https://www.bilibili.com/video/BV1Bg4y1K7yC/
伤心情歌,https://15799848.s21v.faiusr.com/58/ABUIABA6GAAgmvmc4gUo8NSjoQI.mp4
等你等到我心痛,https://15799848.s21v.faiusr.com/58/ABUIABA6GAAg5fTW4gUoypKv_AQ.mp4
高安杭娇_一生无悔,https://15799848.s21v.faiusr.com/58/ABUIABA6GAAgtL6q4gUojIS-mQE.mp4
刚好遇见你,http://15799848.s21v.faiusr.com/58/ABUIABA6GAAg3q6M5gUohPidmQc.mp4
甘心情愿爱着你.安东阳张怡诺,https://15799848.s21v.faiusr.com/58/ABUIABA6GAAgq_2a4gUo686M8wc.mp4
风中花雨楼.任妙音,https://15799848.s21v.faiusr.com/58/ABUIABA6GAAgypLV4gUo-ZmUhwc.mp4
分手.冷漠,https://15799848.s21v.faiusr.com/58/ABUIABA6GAAgwsfE4gUokp27lAQ.mp4
放狠爱.慕容晓晓肖玄,https://15799848.s21v.faiusr.com/58/ABUIABA6GAAgpoLG4gUo0JOBggI.mp4
渡红尘.张碧晨,https://15799848.s21v.faiusr.com/58/ABUIABA6GAAgkN-64wUorOL7mQI.mp4
都说.龙梅子老猫,https://15799848.s21v.faiusr.com/58/ABUIABA6GAAghPbQ7AUohPLwrAM.mp4
丁当_野兽,https://15799848.s21v.faiusr.com/58/ABUIABA6GAAg0MOm4gUo-LnKpQE.mp4
邓紫棋_喜欢你,https://15799848.s21v.faiusr.com/58/ABUIABA6GAAg6uyj4QUosO5G.mp4
等你一万年.白雪,https://15799848.s21v.faiusr.com/58/ABUIABA6GAAgyKyM5gUooJurKA.mp4
等你一万年,http://15799848.s21v.faiusr.com/58/ABUIABA6GAAgyKyM5gUooJurKA.mp4
等到山花开_钟小冰,https://15799848.s21v.faiusr.com/58/ABUIABA6GAAggcOv5wUo4pShggc.mp4
当爱离别时,http://15799848.s21v.faiusr.com/58/ABUIABA6GAAgstTE4gUo856frgY.mp4
当,http://15799848.s21v.faiusr.com/58/ABUIABA6GAAgpPTW4gUoz_DgdQ.mp4
单身情歌_黄晓凤,https://15799848.s21v.faiusr.com/58/ABUIABA6GAAgjfPW4gUo4umD3QE.mp4
错过了缘分错过你_候俊辉,https://15799848.s21v.faiusr.com/58/ABUIABA6GAAgqfLW4gUogNTT1wY.mp4
崔子格老猫_老婆最大,https://15799848.s21v.faiusr.com/58/ABUIABA6GAAg29is4gUopvmF8wI.mp4
传奇_黄晓凤,https://15799848.s21v.faiusr.com/58/ABUIABA6GAAg9b62-AUomeie4gY.mp4
成龙金喜善_美丽的神话,https://15799848.s21v.faiusr.com/58/ABUIABA6GAAg_tma4gUowLvk9wM.mp4
陈慧娴-逝去的诺言,http://bizcommon.alicdn.com/l2nDqpMmn6DGHnWzZQA/i78cWdjCSglPJHDaedL%40%40ld.m3u8
27 changes: 21 additions & 6 deletions src/main/java/com/leosam/tvbox/mv/MainVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public void start(Promise<Void> startPromise) throws Exception {
Router router = Router.router(vertx);
router.route("/mv/search").handler(this::searchMv);
router.route("/mv/vod").handler(this::searchMvVod);
router.route("/vod").handler(this::searchVod);
router.route("/vod/:index").handler(this::searchVod);
router.route("/*").handler(StaticHandler.create("static"));
router.route().handler(this::home);
httpServer.requestHandler(router);
Expand All @@ -63,39 +65,52 @@ public void start(Promise<Void> startPromise) throws Exception {
logger.info("HTTP server started on port 7777");
} else {
startPromise.fail(http.cause());
logger.info("HTTP server fail, on port 7777, 启动失败,更换端口重试", http.cause());
}
});
port = httpServer.actualPort();
}

private void searchMvVod(RoutingContext req) {
searchVod(req, MvService.MV_FILE_NAME);
}

private void searchVod(RoutingContext req) {
searchVod(req, StringUtils.EMPTY);
}

/**
* 参考 <a href="https://github.com/FongMi/TV/blob/release/app/src/main/java/com/fongmi/android/tv/model/SiteViewModel.java#L32">...</a>
* @param req
*/
private void searchMvVod(RoutingContext req) {
private void searchVod(RoutingContext req, String index) {
// 获取参数
String wd = VertxUtils.queryParam(req, "wd");
String ids = VertxUtils.queryParam(req, "ids");
String query = StringUtils.isNotEmpty(wd) ? wd : ids;
String query = StringUtils.trimToEmpty(StringUtils.defaultIfEmpty(wd, ids));
String ac = VertxUtils.queryParam(req, "ac");
String type = VertxUtils.queryParam(req, "t");
//query = StringUtils.isNotEmpty(query) ? query : "我";
String maxCount = VertxUtils.queryParam(req, "maxCount");
int max = Math.min(Math.max(NumberUtils.toInt(maxCount, 200), 10), 1000);
String pg = VertxUtils.queryParam(req, "pg");
int page = NumberUtils.toInt(pg, 0);
if(StringUtils.isEmpty(index)){
String pathIndex = req.pathParam("index");
String queryIndex = VertxUtils.queryParam(req, "index");
index = StringUtils.trimToEmpty(StringUtils.defaultIfEmpty(pathIndex, queryIndex));
}

// 处理结果
VodResult vodResult = null;
try {
// 搜索
if (mvService != null && StringUtils.isNotEmpty(query) && page <= 0) {
vodResult = mvService.searchVod(query, max);
vodResult = mvService.searchVod(index, query, max);
}

// 首页
if (mvService != null && StringUtils.isEmpty(query)) {
vodResult = mvService.searchVodHome(type, page);
vodResult = mvService.searchVodHome(index, type, page);
}

} catch (Exception e) {
Expand All @@ -121,7 +136,7 @@ private void searchMv(RoutingContext req) {
MvResult search = null;
try {
if (mvService != null) {
search = mvService.search(query, max);
search = mvService.search(null, query, max);
}
} catch (Exception e) {
throw new RuntimeException(e);
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/com/leosam/tvbox/mv/lucene/MvSearcher.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package com.leosam.tvbox.mv.lucene;

import com.leosam.tvbox.mv.utils.StringUtils;
import io.vertx.ext.web.impl.LRUCache;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.cn.smart.SmartChineseAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.StoredFields;
import org.apache.lucene.index.Term;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
Expand Down Expand Up @@ -55,6 +60,34 @@ public TopDocs searchTopDocs(String field, String queryStr, int maxHit) throws E
return docs;
}

public TopDocs searchTopDocs(String field, String queryStr, String termField, String termQueryStr, int maxHit) throws Exception {
String cacheKey = field + "_" + queryStr + "_" + termField + "_" + termQueryStr + "_" + maxHit;
TopDocs topDocs = topDocsLruCache.get(cacheKey);
if (topDocs != null) {
return topDocs;
}

BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder();
// 全文检索
if(StringUtils.isNotEmpty(queryStr)){
Analyzer analyzer = new SmartChineseAnalyzer();
// Analyzer analyzer = new StandardAnalyzer();
QueryParser parser = new QueryParser(field, analyzer);
Query query = parser.parse(queryStr);
queryBuilder.add(query, BooleanClause.Occur.MUST);
}
// 关键字检索
if (StringUtils.isNotEmpty(termQueryStr)) {
Query keywordQuery = new TermQuery(new Term(termField, termQueryStr));
queryBuilder.add(keywordQuery, BooleanClause.Occur.MUST);
}
BooleanQuery combinedQuery = queryBuilder.build();

TopDocs docs = searcher.search(combinedQuery, maxHit);
topDocsLruCache.put(cacheKey, docs);
return docs;
}

public void search(String field, String queryStr) throws Exception {
Analyzer analyzer = new SmartChineseAnalyzer();
// Analyzer analyzer = new StandardAnalyzer();
Expand Down
Loading

0 comments on commit 6a214d9

Please sign in to comment.