
jsonStore 应声明为 DocumentStore 类型,这是 OJAI API 中提供 query()、find()(返回 QueryResult,即 DocumentStream 子类)及 getAllDocumentsAsStream() 等核心数据访问方法的标准接口。
`jsonstore` 应声明为 `documentstore` 类型,这是 ojai api 中提供 `query()`、`find()`(返回 `queryresult`,即 `documentstore` 中 `queryresult` 是 `documentstream` 的子类)及 `getalldocumentsasstream()` 等核心数据访问方法的标准接口。
在基于 MapR-DB 或兼容 OJAI(Open JSON Application Interface)的存储系统中,DocumentStore 是执行文档级读写操作的核心接口。它抽象了底层存储(如 MapR-DB JSON table),统一暴露面向 JSON 文档的 CRUD 方法。你代码中调用的 query()、queryAsStream()(实际应为 find().asStream())、getAllDocumentsAsStream() 等功能,均由 DocumentStore 定义并实现。
✅ 正确声明方式如下:
import org.ojai.store.DocumentStore;
import org.ojai.store.QueryCondition;
import org.ojai.store.QueryResult;
import org.ojai.Document;
import org.ojai.DocumentStream;
@Repository
public class AccountRepository extends JsonRepository {
// ✅ 正确类型:DocumentStore(而非 Object 或泛型占位符)
public DocumentStore jsonStore; // 初始化需通过 OJAI connection 获取
public DocumentStream accountsAsStream(List<string> ids) {
// 注意:OJAI 不直接支持 .in(123, ids) —— 正确用法是 QueryCondition.in("field", values)
QueryCondition condition = QueryCondition.create()
.and()
.in("id", ids)
.end();
// ✅ 推荐使用 find() + asStream()(现代 OJAI 实践)
QueryResult result = jsonStore.find(condition);
return result.asStream(); // 返回 DocumentStream
}
public DocumentStream accountIdsAsStream() {
// ✅ getAllDocumentsAsStream 期望字段名(String),用于投影
return jsonStore.getAllDocumentsAsStream("id");
}
}</string>
⚠️ 注意事项:
基于三引擎设计,从微信文章、新闻和博客网页提取干净内容,支持标题作者日期元数据,多格式和批量处理。
-
jsonStore必须通过OJAIConnection.getStore(String tableName)初始化,例如:OJAIConnection connection = connectionFactory.getConnection(); this.jsonStore = connection.getStore("/mapr/demo/table/accounts"); -
queryAsStream()并非DocumentStore的直接方法 —— 当前 OJAI(v3.x+)标准接口已统一使用find(QueryCondition)返回QueryResult,再调用.asStream()获取流式结果;旧版queryAsStream()已弃用。 -
QueryCondition.in()第一个参数是字段名(如"id"),而非数值(123是无效用法),请确保传入合法路径表达式。 - 所有
DocumentStream均为 AutoCloseable,建议在 try-with-resources 中消费,避免资源泄漏。
总结:将 jsonStore 声明为 org.ojai.store.DocumentStore,不仅语义清晰、类型安全,还能完整支持 OJAI 规范定义的查询、流式遍历与批量操作,是构建 MapR-DB / OJAI 应用的推荐实践。










