鏈接器裏面採用的什麼樣的數據結構,咱們先從Document迭代器開始入手,具體的Document迭代器類都實現了DocumentList接口,該接口定義了兩個方法html
public interface DocumentList { public Document nextDocument() throws RepositoryException; public String checkpoint() throws RepositoryException; }
前者用於獲取Document對象,後者獲取斷點狀態json
上文中分析的DiffingConnectorDocumentList類即實現了DocumentList接口,從List<CheckpointAndChange> guaranteedChanges集合的迭代器中迭代獲取CheckpointAndChange對象而後包裝爲Document類型對象數據結構
Document也是一接口類型ide
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結構ui
public interface Property { public Value nextValue() throws RepositoryException; }
下面繼續考察Document接口的具體實現類,以JsonDocument類說明: this
/** *省略了其餘部分紅員屬性及方法 * 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接口spa
/** * 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鏈表相似code
---------------------------------------------------------------------------htm
本系列企業搜索引擎開發之鏈接器connector系本人原創
轉載請註明出處 博客園 刺蝟的溫馴
本人郵箱: chenying998179@163#com (#改成.)