Permalink
Browse files

Reader stuff implementation.

  • Loading branch information...
1 parent 3f3a9b5 commit d70e6387359d54aaeff0041c3c51f75c12f2b782 @gr0 gr0 committed Jan 30, 2012
View
@@ -18,6 +18,12 @@
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ </resource>
+ </resources>
+
<testResources>
<testResource>
<directory>src/test/resources</directory>
@@ -0,0 +1,59 @@
+package com.sematext.searchschemer.index;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * Implementation of {@link IndexStructure}.
+ *
+ * @author Sematext
+ *
+ */
+public class BasicIndexStructure implements IndexStructure {
+ /** Non-dynamic fields. */
+ private Map<String, FieldAttributes> fields;
+
+ /** Dynamic fields. */
+ private Map<String, FieldAttributes> dynamicFields;
+
+ public BasicIndexStructure() {
+ fields = new LinkedHashMap<String, FieldAttributes>();
+ dynamicFields = new LinkedHashMap<String, FieldAttributes>();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Map<String, FieldAttributes> fields() {
+ return fields;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Map<String, FieldAttributes> dynamicFields() {
+ return dynamicFields;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void addField(String name, FieldAttributes attributes) {
+ addField(name, attributes, false);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void addField(String name, FieldAttributes attributes, Boolean dynamic) {
+ if (dynamic) {
+ dynamicFields.put(name, attributes);
+ } else {
+ fields.put(name, attributes);
+ }
+ }
+}
@@ -0,0 +1,51 @@
+package com.sematext.searchschemer.index;
+
+/**
+ * Attributes for a given field.
+ *
+ * @author Sematext
+ *
+ */
+public final class FieldAttributes {
+ private String type;
+ private Boolean indexed;
+ private Boolean stored;
+
+ public FieldAttributes(String type) {
+ this(type, true, false);
+ }
+
+ public FieldAttributes(String type, Boolean indexed) {
+ this(type, indexed, false);
+ }
+
+ public FieldAttributes(String type, Boolean indexed, Boolean stored) {
+ this.type = type;
+ this.indexed = indexed;
+ this.stored = stored;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public Boolean getIndexed() {
+ return indexed;
+ }
+
+ public void setIndexed(Boolean indexed) {
+ this.indexed = indexed;
+ }
+
+ public Boolean getStored() {
+ return stored;
+ }
+
+ public void setStored(Boolean stored) {
+ this.stored = stored;
+ }
+}
@@ -0,0 +1,47 @@
+package com.sematext.searchschemer.index;
+
+import java.util.Map;
+
+/**
+ * Index structure interface.
+ *
+ * @author Sematext
+ *
+ */
+public interface IndexStructure {
+ /**
+ * Get fields for a given index.
+ *
+ * @return map of fields and their attributes
+ */
+ Map<String, FieldAttributes> fields();
+
+ /**
+ * Get dynamic fields for a given index.
+ *
+ * @return map of dynamic fields and their attributes
+ */
+ Map<String, FieldAttributes> dynamicFields();
+
+ /**
+ * Add non-dynamic field.
+ *
+ * @param name
+ * field name
+ * @param attributes
+ * field attributes
+ */
+ void addField(String name, FieldAttributes attributes);
+
+ /**
+ * Add field.
+ *
+ * @param name
+ * field name
+ * @param attributes
+ * field attributes
+ * @param dynamic
+ * <code>true</code> is the field is dynamic, <code>false</code> otherwise
+ */
+ void addField(String name, FieldAttributes attributes, Boolean dynamic);
+}
@@ -0,0 +1,4 @@
+/**
+ * Classes responsible for index structure.
+ */
+package com.sematext.searchschemer.index;
@@ -0,0 +1,25 @@
+package com.sematext.searchschemer.reader;
+
+import java.io.IOException;
+
+import com.sematext.searchschemer.index.IndexStructure;
+
+/**
+ * Implementation of {@link IndexStructureReader} for Elasticsearch.
+ *
+ * @author Sematext
+ *
+ */
+public class ElasticsearchIndexStructureReader implements IndexStructureReader {
+ protected ElasticsearchIndexStructureReader() {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IndexStructure read(String file) throws IOException {
+ //TODO implement
+ return null;
+ }
+}
@@ -0,0 +1,24 @@
+package com.sematext.searchschemer.reader;
+
+import java.io.IOException;
+
+import com.sematext.searchschemer.index.IndexStructure;
+
+/**
+ * Interface for index structure reading functionality.
+ *
+ * @author Sematext
+ *
+ */
+public interface IndexStructureReader {
+ /**
+ * Read index structure details.
+ *
+ * @param file
+ * file holding configuration
+ * @return index structure
+ * @throws IOException
+ * thrown when I/O error occurs
+ */
+ IndexStructure read(String file) throws IOException;
+}
@@ -0,0 +1,36 @@
+package com.sematext.searchschemer.reader;
+
+import com.sematext.searchschemer.client.ConfigurationType;
+
+/**
+ * Factory for index structure readers.
+ *
+ * @author Sematext
+ *
+ */
+public class IndexStructureReaderFactory {
+ /**
+ * Private constructor - no instances.
+ */
+ private IndexStructureReaderFactory() {
+ }
+
+ /**
+ * Returns appropriate reader depending on configuration type.
+ *
+ * @param type
+ * configuration type
+ * @return reader instance
+ */
+ public static IndexStructureReader getReader(ConfigurationType type) {
+ switch (type) {
+ case SOLR:
+ return new SolrIndexStructureReader();
+ case ELASTICSEARCH:
+ return new ElasticsearchIndexStructureReader();
+ case SENSEIDB:
+ return new SenseidbIndexStructureReader();
+ }
+ return null;
+ }
+}
@@ -0,0 +1,25 @@
+package com.sematext.searchschemer.reader;
+
+import java.io.IOException;
+
+import com.sematext.searchschemer.index.IndexStructure;
+
+/**
+ * Implementation of {@link IndexStructureReader} for SenseiDB.
+ *
+ * @author Sematext
+ *
+ */
+public class SenseidbIndexStructureReader implements IndexStructureReader {
+ protected SenseidbIndexStructureReader() {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IndexStructure read(String file) throws IOException {
+ //TODO implement
+ return null;
+ }
+}
@@ -0,0 +1,27 @@
+package com.sematext.searchschemer.reader;
+
+import java.io.IOException;
+
+import com.sematext.searchschemer.index.BasicIndexStructure;
+import com.sematext.searchschemer.index.IndexStructure;
+
+/**
+ * Implementation of {@link IndexStructureReader} for Apache Solr.
+ *
+ * @author Sematext
+ *
+ */
+public class SolrIndexStructureReader implements IndexStructureReader {
+ protected SolrIndexStructureReader() {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IndexStructure read(String file) throws IOException {
+ IndexStructure structure = new BasicIndexStructure();
+ //TODO implementation
+ return structure;
+ }
+}
@@ -0,0 +1,4 @@
+/**
+ * Classes responsible for schema reading.
+ */
+package com.sematext.searchschemer.reader;
@@ -0,0 +1,20 @@
+package com.sematext.searchschemer.reader;
+
+import junit.framework.TestCase;
+
+import org.junit.Test;
+
+import com.sematext.searchschemer.client.ConfigurationType;
+
+public class IndexStructureReaderFactoryTest extends TestCase {
+ @Test
+ public void testGetReader() {
+ assertTrue("SolrIndexStructureReader instance awaited",
+ IndexStructureReaderFactory.getReader(ConfigurationType.SOLR) instanceof SolrIndexStructureReader);
+ assertTrue(
+ "ElasticsearchIndexStructureReader instance awaited",
+ IndexStructureReaderFactory.getReader(ConfigurationType.ELASTICSEARCH) instanceof ElasticsearchIndexStructureReader);
+ assertTrue("SenseidbIndexStructureReader instance awaited",
+ IndexStructureReaderFactory.getReader(ConfigurationType.SENSEIDB) instanceof SenseidbIndexStructureReader);
+ }
+}

0 comments on commit d70e638

Please sign in to comment.