| 1 | |
|
| 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 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
public class DocumentIndexStore implements DocumentStore { |
| 18 | |
List<DocumentIndexReader> readers; |
| 19 | |
|
| 20 | |
public DocumentIndexStore(DocumentIndexReader reader) { |
| 21 | 4 | this(Collections.singletonList(reader)); |
| 22 | 4 | } |
| 23 | |
|
| 24 | 4 | public DocumentIndexStore(List<DocumentIndexReader> readers) { |
| 25 | 4 | this.readers = readers; |
| 26 | 4 | } |
| 27 | |
|
| 28 | |
public Document get(String identifier) throws IOException { |
| 29 | 4 | for (DocumentIndexReader reader : readers) { |
| 30 | 4 | Document document = reader.getDocument(identifier); |
| 31 | 4 | if (document != null) { |
| 32 | 4 | return document; |
| 33 | |
} |
| 34 | 0 | } |
| 35 | 0 | return null; |
| 36 | |
} |
| 37 | |
|
| 38 | |
public void close() throws IOException { |
| 39 | 4 | for (DocumentIndexReader reader : readers) { |
| 40 | 4 | reader.close(); |
| 41 | |
} |
| 42 | 4 | } |
| 43 | |
} |