diff --git a/node/src/main/kotlin/net/corda/node/services/identity/IdentityServiceUtil.kt b/node/src/main/kotlin/net/corda/node/services/identity/IdentityServiceUtil.kt new file mode 100644 index 0000000000..b5f065cc85 --- /dev/null +++ b/node/src/main/kotlin/net/corda/node/services/identity/IdentityServiceUtil.kt @@ -0,0 +1,24 @@ +package net.corda.node.services.identity + +import net.corda.core.identity.CordaX500Name +import net.corda.core.identity.Party + + +fun partiesFromName(query: String, exactMatch: Boolean, x500name: CordaX500Name, results: LinkedHashSet, party: Party) { + + val components = listOfNotNull(x500name.commonName, x500name.organisationUnit, x500name.organisation, x500name.locality, x500name.state, x500name.country) + components.forEach { component -> + if (exactMatch && component == query) { + results += party + } else if (!exactMatch) { + // We can imagine this being a query over a lucene index in future. + // + // Kostas says: We can easily use the Jaro-Winkler distance metric as it is best suited for short + // strings such as entity/company names, and to detect small typos. We can also apply it for city + // or any keyword related search in lists of records (not raw text - for raw text we need indexing) + // and we can return results in hierarchical order (based on normalised String similarity 0.0-1.0). + if (component.contains(query, ignoreCase = true)) + results += party + } + } +} \ No newline at end of file diff --git a/node/src/main/kotlin/net/corda/node/services/identity/InMemoryIdentityService.kt b/node/src/main/kotlin/net/corda/node/services/identity/InMemoryIdentityService.kt index 92e06f437d..4487128d27 100644 --- a/node/src/main/kotlin/net/corda/node/services/identity/InMemoryIdentityService.kt +++ b/node/src/main/kotlin/net/corda/node/services/identity/InMemoryIdentityService.kt @@ -103,22 +103,7 @@ class InMemoryIdentityService(identities: Array, override fun partiesFromName(query: String, exactMatch: Boolean): Set { val results = LinkedHashSet() for ((x500name, partyAndCertificate) in principalToParties) { - val party = partyAndCertificate.party - val components = listOfNotNull(x500name.commonName, x500name.organisationUnit, x500name.organisation, x500name.locality, x500name.state, x500name.country) - components.forEach { component -> - if (exactMatch && component == query) { - results += party - } else if (!exactMatch) { - // We can imagine this being a query over a lucene index in future. - // - // Kostas says: We can easily use the Jaro-Winkler distance metric as it is best suited for short - // strings such as entity/company names, and to detect small typos. We can also apply it for city - // or any keyword related search in lists of records (not raw text - for raw text we need indexing) - // and we can return results in hierarchical order (based on normalised String similarity 0.0-1.0). - if (component.contains(query, ignoreCase = true)) - results += party - } - } + partiesFromName(query, exactMatch, x500name, results, partyAndCertificate.party) } return results } diff --git a/node/src/main/kotlin/net/corda/node/services/identity/PersistentIdentityService.kt b/node/src/main/kotlin/net/corda/node/services/identity/PersistentIdentityService.kt index a8ff0525e0..f2e01d2079 100644 --- a/node/src/main/kotlin/net/corda/node/services/identity/PersistentIdentityService.kt +++ b/node/src/main/kotlin/net/corda/node/services/identity/PersistentIdentityService.kt @@ -180,22 +180,7 @@ class PersistentIdentityService(override val trustRoot: X509Certificate, override fun partiesFromName(query: String, exactMatch: Boolean): Set { val results = LinkedHashSet() for ((x500name, partyId) in principalToParties.allPersisted()) { - val party = keyToParties[partyId]!!.party - val components = listOfNotNull(x500name.commonName, x500name.organisationUnit, x500name.organisation, x500name.locality, x500name.state, x500name.country) - components.forEach { component -> - if (exactMatch && component == query) { - results += party - } else if (!exactMatch) { - // We can imagine this being a query over a lucene index in future. - // - // Kostas says: We can easily use the Jaro-Winkler distance metric as it is best suited for short - // strings such as entity/company names, and to detect small typos. We can also apply it for city - // or any keyword related search in lists of records (not raw text - for raw text we need indexing) - // and we can return results in hierarchical order (based on normalised String similarity 0.0-1.0). - if (component.contains(query, ignoreCase = true)) - results += party - } - } + partiesFromName(query, exactMatch, x500name, results, keyToParties[partyId]!!.party) } return results }