Extracted createFieldsForAccountTransaction()

This commit is contained in:
dankito 2020-04-28 17:01:39 +02:00
parent 3829abe120
commit fb456c451a
1 changed files with 20 additions and 13 deletions

View File

@ -19,6 +19,7 @@ import net.dankito.utils.lucene.index.DocumentsWriter
import net.dankito.utils.lucene.index.FieldBuilder import net.dankito.utils.lucene.index.FieldBuilder
import net.dankito.utils.serialization.ISerializer import net.dankito.utils.serialization.ISerializer
import net.dankito.utils.serialization.JacksonJsonSerializer import net.dankito.utils.serialization.JacksonJsonSerializer
import org.apache.lucene.index.IndexableField
import java.io.File import java.io.File
@ -36,19 +37,7 @@ open class LuceneBankingPersistence(
DocumentsWriter(LuceneConfig.getAccountTransactionsIndexFolder(indexFolder)).use { writer -> DocumentsWriter(LuceneConfig.getAccountTransactionsIndexFolder(indexFolder)).use { writer ->
transactions.forEach { transaction -> transactions.forEach { transaction ->
writer.updateDocumentForNonNullFields(IdFieldName, transaction.id, writer.updateDocumentForNonNullFields(IdFieldName, transaction.id,
fields.keywordField(BankAccountIdFieldName, bankAccount.id), *createFieldsForAccountTransaction(bankAccount, transaction).toTypedArray()
fields.nullableFullTextSearchField(OtherPartyNameFieldName, transaction.otherPartyName, true),
fields.fullTextSearchField(UsageFieldName, transaction.usage, true),
fields.nullableFullTextSearchField(BookingTextFieldName, transaction.bookingText, true),
fields.nullableStoredField(OtherPartyBankCodeFieldName, transaction.otherPartyBankCode),
fields.nullableStoredField(OtherPartyAccountIdFieldName, transaction.otherPartyAccountId),
fields.storedField(BookingDateFieldName, transaction.bookingDate),
fields.storedField(AmountFieldName, transaction.amount),
fields.storedField(CurrencyFieldName, transaction.currency),
fields.nullableStoredField(BalanceFieldName, transaction.balance),
fields.sortField(BookingDateSortFieldName, transaction.bookingDate)
) )
} }
@ -56,4 +45,22 @@ open class LuceneBankingPersistence(
} }
} }
protected open fun createFieldsForAccountTransaction(bankAccount: BankAccount, transaction: AccountTransaction): List<IndexableField?> {
return listOf(
fields.keywordField(BankAccountIdFieldName, bankAccount.id),
fields.nullableFullTextSearchField(OtherPartyNameFieldName, transaction.otherPartyName, true),
fields.fullTextSearchField(UsageFieldName, transaction.usage, true),
fields.nullableFullTextSearchField(BookingTextFieldName, transaction.bookingText, true),
fields.nullableStoredField(OtherPartyBankCodeFieldName, transaction.otherPartyBankCode),
fields.nullableStoredField(OtherPartyAccountIdFieldName, transaction.otherPartyAccountId),
fields.storedField(BookingDateFieldName, transaction.bookingDate),
fields.storedField(AmountFieldName, transaction.amount),
fields.storedField(CurrencyFieldName, transaction.currency),
fields.nullableStoredField(BalanceFieldName, transaction.balance),
fields.sortField(BookingDateSortFieldName, transaction.bookingDate)
)
}
} }