Skip to content

Commit 0c37e61

Browse files
committed
HSEARCH-2500 Test list of PDF as Set<String>
1 parent 12f566a commit 0c37e61

File tree

4 files changed

+66
-6
lines changed

4 files changed

+66
-6
lines changed
Binary file not shown.

orm/src/test/java/org/hibernate/search/test/bridge/tika/Book.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88

99
import java.net.URI;
1010
import java.sql.Blob;
11+
import java.util.HashSet;
12+
import java.util.Set;
1113

1214
import javax.persistence.Basic;
15+
import javax.persistence.ElementCollection;
1316
import javax.persistence.Entity;
1417
import javax.persistence.FetchType;
1518
import javax.persistence.GeneratedValue;
@@ -18,6 +21,7 @@
1821

1922
import org.hibernate.search.annotations.Field;
2023
import org.hibernate.search.annotations.Indexed;
24+
import org.hibernate.search.annotations.IndexedEmbedded;
2125
import org.hibernate.search.annotations.TikaBridge;
2226

2327
/**
@@ -32,9 +36,19 @@ public class Book {
3236
private byte[] contentAsBytes;
3337
private URI contentAsURI;
3438

39+
private Set<String> contentAsListOfString;
40+
3541
public Book() {
3642
}
3743

44+
public Book(String... contents) {
45+
Set<String> temp = new HashSet<>();
46+
for ( String string : contents ) {
47+
temp.add( string );
48+
}
49+
this.contentAsListOfString = temp;
50+
}
51+
3852
public Book(Blob content) {
3953
this.contentAsBlob = content;
4054
}
@@ -81,7 +95,6 @@ public void setContentAsBytes(byte[] contentAsBytes) {
8195
this.contentAsBytes = contentAsBytes;
8296
}
8397

84-
@Lob
8598
@Basic(fetch = FetchType.LAZY)
8699
@Field(indexNullAs = "<NULL>")
87100
@TikaBridge
@@ -92,4 +105,16 @@ public URI getContentAsURI() {
92105
public void setContentAsURI(URI contentAsURI) {
93106
this.contentAsURI = contentAsURI;
94107
}
108+
109+
@IndexedEmbedded
110+
@Field
111+
@TikaBridge
112+
@ElementCollection
113+
public Set<String> getContentAsListOfString() {
114+
return contentAsListOfString;
115+
}
116+
117+
public void setContentAsListOfString(Set<String> contentAsListOfString) {
118+
this.contentAsListOfString = contentAsListOfString;
119+
}
95120
}

orm/src/test/java/org/hibernate/search/test/bridge/tika/TikaBridgeInputTypeTest.java

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,50 @@
4141
* @author Hardy Ferentschik
4242
*/
4343
public class TikaBridgeInputTypeTest extends SearchTestBase {
44-
private static final String TEST_DOCUMENT_PDF = "/org/hibernate/search/test/bridge/tika/test-document-1.pdf";
44+
45+
private static final String TEST_DOCUMENT_PDF_1 = "/org/hibernate/search/test/bridge/tika/test-document-1.pdf";
46+
private static final String TEST_DOCUMENT_PDF_2 = "/org/hibernate/search/test/bridge/tika/test-document-2.pdf";
47+
48+
@Rule
49+
public ClasspathResourceAsFile testDocumentPdf1 = new ClasspathResourceAsFile( getClass(), TEST_DOCUMENT_PDF_1 );
4550

4651
@Rule
47-
public ClasspathResourceAsFile testDocumentPdf = new ClasspathResourceAsFile( getClass(), TEST_DOCUMENT_PDF );
52+
public ClasspathResourceAsFile testDocumentPdf2 = new ClasspathResourceAsFile( getClass(), TEST_DOCUMENT_PDF_2 );
53+
54+
@Test
55+
public void testDefaultTikaBridgeWithListOfString() throws Exception {
56+
try ( Session session = openSession() ) {
57+
String content1 = testDocumentPdf1.get().getAbsolutePath();
58+
String content2 = testDocumentPdf2.get().getAbsolutePath();
59+
60+
persistBook( session, new Book( content1, content2 ) );
61+
62+
indexBook( session );
63+
64+
List<Book> resultWithLucene = search( session, "contentAsListOfString", "Lucene" );
65+
assertEquals( "there should be a match", 1, resultWithLucene.size() );
66+
67+
List<Book> resultWithTika = search( session, "contentAsListOfString", "Tika" );
68+
assertEquals( "there should be a match", 1, resultWithTika.size() );
69+
}
70+
}
71+
72+
private List<Book> search(Session session, String field, String keyword) throws ParseException {
73+
FullTextSession fullTextSession = Search.getFullTextSession( session );
74+
Transaction transaction = fullTextSession.beginTransaction();
75+
QueryParser parser = new QueryParser( field, TestConstants.standardAnalyzer );
76+
Query query = parser.parse( keyword );
77+
@SuppressWarnings("unchecked")
78+
List<Book> result = fullTextSession.createFullTextQuery( query ).list();
79+
transaction.commit();
80+
fullTextSession.clear();
81+
return result;
82+
}
4883

4984
@Test
5085
public void testDefaultTikaBridgeWithBlob() throws Exception {
5186
try ( Session session = openSession() ) {
52-
Blob content = dataAsBlob( testDocumentPdf.get(), session );
87+
Blob content = dataAsBlob( testDocumentPdf1.get(), session );
5388

5489
persistBook( session, new Book( content ) );
5590
persistBook( session, new Book() );
@@ -64,7 +99,7 @@ public void testDefaultTikaBridgeWithBlob() throws Exception {
6499
@Test
65100
public void testDefaultTikaBridgeWithByteArray() throws Exception {
66101
try ( Session session = openSession() ) {
67-
byte[] content = dataAsBytes( testDocumentPdf.get() );
102+
byte[] content = dataAsBytes( testDocumentPdf1.get() );
68103

69104
persistBook( session, new Book( content ) );
70105
persistBook( session, new Book() );
@@ -77,7 +112,7 @@ public void testDefaultTikaBridgeWithByteArray() throws Exception {
77112
@Test
78113
public void testDefaultTikaBridgeWithURI() throws Exception {
79114
try ( Session session = openSession() ) {
80-
URI content = testDocumentPdf.get().toURI();
115+
URI content = testDocumentPdf1.get().toURI();
81116

82117
persistBook( session, new Book( content ) );
83118
persistBook( session, new Book() );
Binary file not shown.

0 commit comments

Comments
 (0)