package be.simplenotes.search import be.simplenotes.domain.model.PersistedNote import be.simplenotes.domain.model.PersistedNoteMetadata import org.apache.lucene.document.Document import org.apache.lucene.document.Field import org.apache.lucene.document.StringField import org.apache.lucene.document.TextField import org.apache.lucene.search.IndexSearcher import org.apache.lucene.search.TopDocs internal fun PersistedNote.toDocument(): Document { val note = this return Document().apply { // non searchable fields add(StringField(uuidField, UuidFieldConverter.toDoc(note.uuid), Field.Store.YES)) add(StringField(updatedAtField, LocalDateTimeFieldConverter.toDoc(note.updatedAt), Field.Store.YES)) // searchable fields add(TextField(titleField, note.meta.title, Field.Store.YES)) add(TextField(tagsField, TagsFieldConverter.toDoc(note.meta.tags), Field.Store.YES)) add(TextField(contentField, note.html, Field.Store.YES)) } } internal fun Document.toNoteMeta() = PersistedNoteMetadata( title = get(titleField), uuid = UuidFieldConverter.fromDoc(get(uuidField)), updatedAt = LocalDateTimeFieldConverter.fromDoc(get(updatedAtField)), tags = TagsFieldConverter.fromDoc(get(tagsField)) )