Search in sources :

Example 11 with StorageException

use of edu.uci.ics.textdb.api.exception.StorageException in project textdb by TextDB.

the class MedlineIndexWriter method writeMedlineIndex.

public static void writeMedlineIndex(Path medlineFilepath, String tableName) throws IOException, StorageException, ParseException {
    RelationManager relationManager = RelationManager.getRelationManager();
    DataWriter dataWriter = relationManager.getTableDataWriter(tableName);
    dataWriter.open();
    BufferedReader reader = Files.newBufferedReader(medlineFilepath);
    String line;
    while ((line = reader.readLine()) != null) {
        try {
            dataWriter.insertTuple(recordToTuple(line));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    reader.close();
    dataWriter.close();
}
Also used : BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) StorageException(edu.uci.ics.textdb.api.exception.StorageException) ParseException(java.text.ParseException) RelationManager(edu.uci.ics.textdb.storage.RelationManager) DataWriter(edu.uci.ics.textdb.storage.DataWriter)

Example 12 with StorageException

use of edu.uci.ics.textdb.api.exception.StorageException in project textdb by TextDB.

the class DataReader method getNextTuple.

@Override
public Tuple getNextTuple() throws StorageException {
    if (cursor == CLOSED) {
        throw new StorageException(ErrorMessages.OPERATOR_NOT_OPENED);
    }
    Tuple resultTuple;
    try {
        if (cursor >= scoreDocs.length) {
            return null;
        }
        int docID = scoreDocs[cursor].doc;
        resultTuple = constructTuple(docID);
    } catch (IOException | ParseException e) {
        throw new StorageException(e.getMessage(), e);
    }
    cursor++;
    return resultTuple;
}
Also used : IOException(java.io.IOException) ParseException(java.text.ParseException) StorageException(edu.uci.ics.textdb.api.exception.StorageException)

Example 13 with StorageException

use of edu.uci.ics.textdb.api.exception.StorageException in project textdb by TextDB.

the class DataReader method open.

@Override
public void open() throws StorageException {
    if (cursor != CLOSED) {
        return;
    }
    try {
        String indexDirectoryStr = this.dataStore.getDataDirectory();
        Directory indexDirectory = FSDirectory.open(Paths.get(indexDirectoryStr));
        luceneIndexReader = DirectoryReader.open(indexDirectory);
        luceneIndexSearcher = new IndexSearcher(luceneIndexReader);
        TopDocs topDocs = luceneIndexSearcher.search(query, Integer.MAX_VALUE);
        scoreDocs = topDocs.scoreDocs;
        inputSchema = this.dataStore.getSchema();
        if (payloadAdded) {
            outputSchema = Utils.addAttributeToSchema(inputSchema, SchemaConstants.PAYLOAD_ATTRIBUTE);
        } else {
            outputSchema = inputSchema;
        }
    } catch (IOException e) {
        throw new StorageException(e.getMessage(), e);
    }
    cursor = OPENED;
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TopDocs(org.apache.lucene.search.TopDocs) IOException(java.io.IOException) StorageException(edu.uci.ics.textdb.api.exception.StorageException) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory)

Example 14 with StorageException

use of edu.uci.ics.textdb.api.exception.StorageException in project textdb by TextDB.

the class DataWriter method open.

public void open() throws StorageException {
    if (this.luceneIndexWriter == null || !this.luceneIndexWriter.isOpen()) {
        try {
            Directory directory = FSDirectory.open(Paths.get(this.indexDirectory));
            IndexWriterConfig conf = new IndexWriterConfig(analyzer);
            this.luceneIndexWriter = new IndexWriter(directory, conf);
            this.isOpen = true;
        } catch (IOException e) {
            throw new StorageException(e.getMessage(), e);
        }
    }
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) IOException(java.io.IOException) StorageException(edu.uci.ics.textdb.api.exception.StorageException) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 15 with StorageException

use of edu.uci.ics.textdb.api.exception.StorageException in project textdb by TextDB.

the class RelationManager method initializeCatalog.

/*
     * Initializes the system catalog tables.
     */
private void initializeCatalog() throws StorageException {
    try {
        // create table catalog
        writeTableInfoToCatalog(CatalogConstants.TABLE_CATALOG.toLowerCase(), new File(CatalogConstants.TABLE_CATALOG_DIRECTORY).getCanonicalPath(), CatalogConstants.TABLE_CATALOG_SCHEMA, LuceneAnalyzerConstants.standardAnalyzerString());
        // create schema catalog
        writeTableInfoToCatalog(CatalogConstants.SCHEMA_CATALOG.toLowerCase(), new File(CatalogConstants.SCHEMA_CATALOG_DIRECTORY).getCanonicalPath(), CatalogConstants.SCHEMA_CATALOG_SCHEMA, LuceneAnalyzerConstants.standardAnalyzerString());
    } catch (IOException e) {
        throw new StorageException(e);
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) StorageException(edu.uci.ics.textdb.api.exception.StorageException)

Aggregations

StorageException (edu.uci.ics.textdb.api.exception.StorageException)22 IOException (java.io.IOException)14 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)9 IField (edu.uci.ics.textdb.api.field.IField)4 Schema (edu.uci.ics.textdb.api.schema.Schema)4 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)4 Query (org.apache.lucene.search.Query)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 DataFlowException (edu.uci.ics.textdb.api.exception.DataFlowException)3 IDField (edu.uci.ics.textdb.api.field.IDField)3 Attribute (edu.uci.ics.textdb.api.schema.Attribute)3 DataWriter (edu.uci.ics.textdb.storage.DataWriter)3 File (java.io.File)3 Term (org.apache.lucene.index.Term)3 TermQuery (org.apache.lucene.search.TermQuery)3 StringField (edu.uci.ics.textdb.api.field.StringField)2 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 Analyzer (org.apache.lucene.analysis.Analyzer)2