@Override public Collection<Document> toDocuments(LuceneIndex index, Object value) { if (value == null) { return Collections.emptyList(); } LuceneSerializer mapper = getFieldMapper(value, index.getFieldNames()); Collection<Document> docs = mapper.toDocuments(index, value); if (logger.isDebugEnabled()) { logger.debug("HeterogeneousLuceneSerializer.toDocuments:" + docs); } return docs; }
/** * Recursively serialize each indexed field's value into a field of lucene document. The field * name will be in the same format as its indexed, such as contacts.homepage.content * * @param index lucene index * @param value user object to be serialized into index */ @Override public Collection<Document> toDocuments(LuceneIndex index, Object value) { String[] fields = index.getFieldNames(); Document doc = new Document(); for (String indexedFieldName : fields) { List<String> tokenizedFields = tokenizeField(indexedFieldName); addFieldValue(doc, indexedFieldName, value, tokenizedFields); } if (logger.isDebugEnabled()) { logger.debug("FlatFormatSerializer.toDocuments: " + doc); } return Collections.singleton(doc); }
@Override public Collection<Document> toDocuments(LuceneIndex index, Object value) { Document doc = new Document(); PdxInstance pdx = (PdxInstance) value; for (String field : index.getFieldNames()) { if (pdx.hasField(field)) { Object fieldValue = pdx.getField(field); if (fieldValue == null) { continue; } SerializerUtil.addField(doc, field, fieldValue); } } if (logger.isDebugEnabled()) { logger.debug("PdxLuceneSerializer.toDocument:" + doc); } return Collections.singleton(doc); } }
public static Document invokeSerializer(LuceneSerializer mapper, Object object, String[] fields) { LuceneIndex index = Mockito.mock(LuceneIndex.class); Mockito.when(index.getFieldNames()).thenReturn(fields); Collection<Document> docs = mapper.toDocuments(index, object); assertEquals(1, docs.size()); return docs.iterator().next(); } }
private IndexRepositoryImpl createIndexRepo() throws IOException { ConcurrentHashMap fileAndChunkRegion = new ConcurrentHashMap(); RegionDirectory dir = new RegionDirectory(fileAndChunkRegion, fileSystemStats); IndexWriterConfig config = new IndexWriterConfig(analyzer); IndexWriter writer = new IndexWriter(dir, config); LuceneIndex index = Mockito.mock(LuceneIndex.class); Mockito.when(index.getFieldNames()).thenReturn(new String[] {"txt"}); return new IndexRepositoryImpl(region, writer, mapper, indexStats, null, null, "", index); }
when(mockLuceneIndex.getFieldNames()).thenAnswer(in -> fields.toArray(new String[fields.size()])); when(mockLuceneIndex.getLuceneSerializer()).thenAnswer(in -> luceneSerializerReference.get()); when(mockLuceneIndex.getName()).thenReturn(indexName);