01: package net.bagaluten.jca.lucene.connector.test;
02:
03: import java.io.PrintWriter;
04: import java.util.HashSet;
05: import java.util.Set;
06:
07: import javax.resource.ResourceException;
08:
09: import net.bagaluten.jca.lucene.connector.Entries;
10: import net.bagaluten.jca.lucene.connector.Entry;
11: import net.bagaluten.jca.lucene.connector.Field;
12: import net.bagaluten.jca.lucene.connector.QueryField;
13: import net.bagaluten.jca.lucene.connector.impl.LuceneConnectionRequestInfo;
14: import net.bagaluten.jca.lucene.connector.impl.LuceneManagedConnection;
15:
16: import org.junit.Before;
17: import org.junit.Test;
18:
19: public class ConnectorTest {
20:
21: private static final String PATH = "c:\\temp\\";
22:
23: private final LuceneManagedConnection mc = new LuceneManagedConnection(
24: new LuceneConnectionRequestInfo("lucene-test"),
25: new PrintWriter(System.out), PATH);
26:
27: public ConnectorTest() throws Exception {
28:
29: }
30:
31: @Before
32: public void setUp() throws Exception {
33: }
34:
35: @Test
36: public void write() throws ResourceException {
37: Entries entries = new Entries();
38: for (int j = 0; j < 20; j++) {
39: Entry entry = entries.createEntry();
40: for (int i = 0; i < 5; i++) {
41: String name = "field-" + i;
42: Field f = new Field("This is content " + i + "-" + j,
43: Field.Index.TOKENIZED, Field.Store.YES);
44: entry.put(name, f);
45: }
46: }
47: mc.bulkAdd(entries);
48: }
49:
50: @Test
51: public void search() throws ResourceException {
52:
53: Set<QueryField> fields = new HashSet<QueryField>();
54:
55: fields.add(new QueryField("field-1"));
56: fields.add(new QueryField("field-3"));
57:
58: Entries result = mc.search("field-1:content", fields, 0, 10);
59: for (Entry entry : result) {
60: for (java.util.Map.Entry<String, Field> f : entry
61: .entrySet()) {
62: System.out.println(f.getKey() + ""
63: + f.getValue().getString());
64: }
65: System.out.println("-----------------------");
66: }
67: }
68: }
|