00001
00002 package de.aitools.aq.invertedindex.usage;
00003
00004 import java.io.File;
00005
00006 import de.aitools.aq.invertedindex.core.Configuration;
00007 import de.aitools.aq.invertedindex.core.Configuration.KeySorting;
00008 import de.aitools.aq.invertedindex.core.Configuration.ValueSorting;
00009 import de.aitools.aq.invertedindex.core.Indexer;
00010 import de.aitools.aq.invertedindex.core.Properties;
00011 import de.aitools.aq.util.Memory;
00012 import de.aitools.aq.util.Record;
00013 import de.aitools.aq.value.single.SingleLong;
00014
00023 public class UsingIndexer {
00024
00025 public static void main(String[] args) {
00026
00027
00028
00029
00030 Configuration config = new Configuration();
00031 config.setIndexDirectory(new File("/path/to/your/index"));
00032 config.setKeySorting(KeySorting.UNSORTED);
00033 config.setValueSorting(ValueSorting.ASCENDING);
00034 config.setMaxMemoryUsage(Memory.MB1024);
00035
00036
00037
00038 config.setExpectedNumberOfRecords(Short.MAX_VALUE);
00039
00040
00041
00042
00043 Class<SingleLong> valueClass = SingleLong.class;
00044 Indexer<SingleLong> indexer = Indexer.open(valueClass, config);
00045
00046
00047
00048
00049 for (int i = 0; i != Short.MAX_VALUE; ++i) {
00050
00051 String key = "key" + (i % Byte.MAX_VALUE);
00052
00053 SingleLong value = new SingleLong(i);
00054
00055 indexer.put(new Record<SingleLong>(key, value));
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 if (i == 1000) {
00069 indexer.setExpectedNumberOfRecords(Short.MAX_VALUE);
00070 }
00071 }
00072
00073 Properties props = indexer.index();
00074
00075 props.printTo(System.out).println();
00076 }
00077 }