View Javadoc

1   // BSD License (http://www.galagosearch.org/license)
2   
3   package org.galagosearch.core.store;
4   
5   import java.io.IOException;
6   import java.util.Collections;
7   import java.util.List;
8   import org.galagosearch.core.parse.Document;
9   import org.galagosearch.core.parse.DocumentIndexReader;
10  
11  /***
12   * <p>A DocumentStore that reads document data from corpus files.</p>
13   * A DocumentIndexStore checks the corpus files sequentially until
14   * it finds a matching document.</p>
15   * @author trevor
16   */
17  public class DocumentIndexStore implements DocumentStore {
18      List<DocumentIndexReader> readers;
19  
20      public DocumentIndexStore(DocumentIndexReader reader) {
21          this(Collections.singletonList(reader));
22      }
23  
24      public DocumentIndexStore(List<DocumentIndexReader> readers) {
25          this.readers = readers;
26      }
27  
28      public Document get(String identifier) throws IOException {
29          for (DocumentIndexReader reader : readers) {
30              Document document = reader.getDocument(identifier);
31              if (document != null) {
32                  return document;
33              }
34          }
35          return null;
36      }
37  
38      public void close() throws IOException {
39          for (DocumentIndexReader reader : readers) {
40              reader.close();
41          }
42      }
43  }