Builds and runs the Elasticsearch queries behind lead management search and filtering. It also supplies the profile and organisation search used by lead-related admin pages, and the query building that the platform's omni-search reuses for leads, profiles and organisations. This is the current (V2) implementation, reached from LeadManager's getSearchV2 accessor. Access is restricted by the caller's applicable lead roles (Sales, TakeLead, SalesManager, SalesTeamViewer) or Administrator status, resolved per organisation via a hierarchy-aware role lookup.


Methods

doLeadSearch(String fieldType, String queryString, List<String> teams, List<Long> filterGroups, List<String> sourcesFilter, List<String> assignedToFilter, List<String> funnelsFilter, List<String> stagesCriteria, SearchProperties props, boolean usePaging)

Returns: KSearchResponse

Searches leads for the lead list and reporting views, applying status, team, group, source, assigned-to, funnel and stage filters on top of the shared lead visibility restriction. Also aggregates the distinct sources and stages present in the results, and the total and average deal amount.

ParameterDescription
fieldTyperestricts by lead status: "active", "closed" or "cancelled"; any other value (including blank) defaults to active leads
queryStringthe free-text search query
teamsorganisation ids to restrict results to leads assigned to those teams; "ALL" or empty disables the filter
filterGroupsprofile group ids to restrict results to leads whose profile belongs to one of the groups
sourcesFilterlead source values to filter by; "NOSOURCE" matches leads with no source recorded
assignedToFilterprofile ids to filter by assignment; "ALL" disables the filter and "NONE" matches unassigned leads
funnelsFilterfunnel names to restrict results to; if empty, all non-hidden-to-sales funnels are used
stagesCriteriastage names to restrict results to
propspaging, page size and sort settings for the request
usePagingwhether the request should apply paging

getBaseLeadQuery(String queryString, List<String> teams, List<Long> filterGroups, List<String> sourcesFilter, List<String> assignedToFilter, List<String> funnels, List<String> stages)

Returns: BoolQueryBuilder

Builds the query used to search leads, applying the free-text match, team, group, source, assigned-to, funnel and stage filters together with the visibility restriction for the current user, but does not run it. Used by callers that need to combine lead criteria with further conditions of their own.

ParameterDescription
queryStringthe free-text search query
teamsorganisation ids to restrict results to leads assigned to those teams; "ALL" or empty disables the filter
filterGroupsprofile group ids to restrict results to leads whose profile belongs to one of the groups
sourcesFilterlead source values to filter by; "NOSOURCE" matches leads with no source recorded
assignedToFilterprofile ids to filter by assignment; "ALL" disables the filter and "NONE" matches unassigned leads
funnelsfunnel names to restrict results to; if empty, all non-hidden-to-sales funnels are used
stagesstage names to restrict results to

appendLeadOmniQuery(BoolQueryBuilder qbMain, String q, Set<String> outputFields, List<String> highlightFields, Set<AppIndexer> indexers, RootFolder rf)

Returns: void

Adds lead results to a combined omni-search query, boosting lead matches above other entity types and excluding cancelled and closed leads. Does nothing if the current user has no applicable lead access role. Registers the lead indexer and its output fields with the caller's search request as a side effect.

ParameterDescription
qbMainthe omni-search query being built; mutated in place
qthe free-text search query
outputFieldsthe set of output fields for the omni-search request; lead fields are added to it
highlightFieldsfields to highlight in the response; currently unused by this method
indexersthe set of indexers included in the omni-search request; the lead indexer is added to it
rfthe root folder the search is scoped to; currently unused by this method

appendEntityOmniQuery(BoolQueryBuilder qbMain, String q, Set<String> outputFields, List<String> highlightFields, Set<AppIndexer> indexers, RootFolder rf)

Returns: void

Adds matching profiles and organisations to a combined omni-search query. Profile results are only added if the current user has access to search profiles, and are boosted above other entity types; organisation results are restricted to the tenant's configured lead and sales organisation types, if any, and are only added if the user has access to search organisations.

ParameterDescription
qbMainthe omni-search query being built; mutated in place
qthe free-text search query
outputFieldsthe set of output fields for the omni-search request; currently unused by this method
highlightFieldsfields to highlight in the response; currently unused by this method
indexersthe set of indexers included in the omni-search request; the profile and/or organisation indexers are added to it
rfthe root folder the search is scoped to; currently unused by this method

entitySearch(String q, Integer start, Integer max)

Returns: KSearchResponse

Searches profiles and organisations together for a lead management omni-search box, matching on either a profile or an organisation the current user has access to search. The organisation search is scoped to the tenant's configured lead org type, if any.

ParameterDescription
qthe free-text search query
startintended start offset for paging; currently unused
maxintended maximum number of results; currently unused

profileSearch(String q, Integer start, Integer max, Map<String,List<String>> selTerms, String sortField, String sortdir, List<String> outputFields)

Returns: KSearchResponse

Searches lead-related profiles, delegating to the paged overload with paging disabled.

ParameterDescription
qthe free-text search query
startthe offset of the first result to return
maxthe maximum number of results to return
selTermsselected facet terms to filter by, keyed by field name
sortFieldthe field to sort results by
sortdirthe sort direction, "DESC" for descending, otherwise ascending
outputFieldsthe fields to include in each search hit

profileSearch(String q, Integer start, Integer max, boolean usePaging, Map<String,List<String>> selTerms, String sortField, String sortdir, List<String> outputFields)

Returns: KSearchResponse

Searches lead-related profiles that the current user has access to, restricting results to profiles in the lead management group and aggregating the most recent SMS and email item per profile and the number of distinct organisations and groups represented in the results.

ParameterDescription
qthe free-text search query
startthe offset of the first result to return
maxthe maximum number of results to return, defaults to 200 if null
usePagingwhether the request should apply paging
selTermsselected facet terms to filter by, keyed by field name
sortFieldthe field to sort results by; "Name" sorts by surname then first name
sortdirthe sort direction, "DESC" for descending, otherwise ascending
outputFieldsthe fields to include in each search hit

orgSearch(String query, SearchProperties searchProperties, Boolean paging)

Returns: KSearchResponse

Searches organisations of the tenant's configured lead organisation type, matching the query text against title, address and identifier fields and restricting results to organisations the current user can see. Returns null if no lead organisation type is configured for the tenant.

ParameterDescription
querythe free-text search query
searchPropertiespaging and sort settings to apply to the request; may be null
pagingwhether the request should apply paging
To get full access to the Kademi Hub existing customers can login here, or new customers can register here.