连接器里面采用的什么样的数据结构,我们先从Document迭代器开始入手,具体的Document迭代器类都实现了DocumentList接口,该接口定义了两个方法
public interface DocumentList { public Document nextDocument() throws RepositoryException; public String checkpoint() throws RepositoryException; }
前者用于获取Document对象,后者获取断点状态
上文中分析的DiffingConnectorDocumentList类即实现了DocumentList接口,从List<CheckpointAndChange> guaranteedChanges集合的迭代器中迭代获取CheckpointAndChange对象然后包装为Document类型对象
Document也是一接口类型
public interface Document { public Property findProperty(String name) throws RepositoryException; public Set<String> getPropertyNames() throws RepositoryException; }
从Document接口定义的方法可以看出,Document接口类似于Map容器结构,如果进一步考察String类型的key对应的value类型Property,可以发现Document接口很类似于HashMap结构
public interface Property { public Value nextValue() throws RepositoryException; }
下面继续考察Document接口的具体实现类,以JsonDocument类说明:
/** *省略了其他部分成员属性及方法 * A simple {@link Document} implementation created from a {@link JSONObject}. */ public class JsonDocument implements Document { private final Map<String, List<Value>> properties; /** * Constructor used by {@link DBHandle} when deserializing a * {@code DocumentHandle} from the recovery file. */ public JsonDocument(JSONObject jsonObject) { this(buildJsonProperties(jsonObject), jsonObject); } /** * Constructor used by the {@link DocumentBuilder} for creating a * {@link JsonDocument} object used by {@link RepositoryHandler} * for building a collection over JsonDocument. */ public JsonDocument(Map<String, List<Value>> properties, JSONObject jsonObject) { this.properties = properties; this.jsonObject = jsonObject; objectId = getSingleValueString(SpiConstants.PROPNAME_DOCID); if (Strings.isNullOrEmpty(objectId)) { throw new IllegalArgumentException( "Unable to parse for docID from the properties:" + properties); } } @Override public Set<String> getPropertyNames() { return properties.keySet(); } @Override public Property findProperty(String name) throws RepositoryException { List<Value> property = properties.get(name); if (name.equals(SpiConstants.PROPNAME_CONTENT) && filterMimeType()) { property = null; } return (property == null) ? null : new SimpleProperty(property); } }
JsonDocument类还有什么好说的呢,内部实际是对Map<String, List<Value>> properties的封装
属性类型SimpleProperty实现了Property接口
/** * Simple implementation of the {@link Property} interface. * Implementors may use this directly or for reference. * * @since 1.0 */ public class SimpleProperty implements Property { final Iterator<Value> iterator; /** * Constructs a property with a single value. * * @param value the property's {@link Value} * @since 2.4 */ public SimpleProperty(Value value) { this(Collections.singletonList(value)); } /** * Constructs a property with multiple values. * * @param values a {@code List} of the property's {@link Value Values} */ public SimpleProperty(List<Value> values) { this.iterator = values.iterator(); } @Override public Value nextValue() { return (iterator.hasNext()) ? iterator.next() : null; } }
成员属性final Iterator<Value> iterator保存值的迭代器,功能与HashMap的entry链表类似
---------------------------------------------------------------------------
本系列企业搜索引擎开发之连接器connector系本人原创
转载请注明出处 博客园 刺猬的温驯
本人邮箱: chenying998179@163#com (#改为.)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
2013-06-15 WEB数据挖掘(十二)——Aperture数据抽取(8):在Aperture中重要的API
2013-06-15 WEB数据挖掘(十一)——Aperture数据抽取(7):在Aperture中重要的API