Hierarchical Menu
HierarchicalConnector( searcher: SearcherSingleIndex, attribute: Attribute, filterState: FilterState, hierarchicalAttributes: List<Attribute>, separator: String )
About this widget
Hierarchical Menu is a filtering view that displays a hierarchy of facets which lets the user refine the search results.
Examples
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class MyActivity : AppCompatActivity() {
val client = ClientSearch(
ApplicationID("YourApplicationID"),
APIKey("YourAPIKey")
)
val index = client.initIndex(IndexName("YourIndexName"))
val searcher = SearcherSingleIndex(index)
val hierarchicalCategory = Attribute("hierarchicalCategories")
val hierarchicalCategoryLvl0 = Attribute("$hierarchicalCategory.lvl0")
val hierarchicalCategoryLvl1 = Attribute("$hierarchicalCategory.lvl1")
val hierarchicalCategoryLvl2 = Attribute("$hierarchicalCategory.lvl2")
val hierarchicalAttributes = listOf(
hierarchicalCategoryLvl0,
hierarchicalCategoryLvl1,
hierarchicalCategoryLvl2
)
val filterState = FilterState()
val separator = " > "
val hierarchical = HierarchicalConnector(
searcher = searcher,
attribute = hierarchicalCategory,
filterState = filterState,
hierarchicalAttributes = hierarchicalAttributes,
separator = separator
)
val connection = ConnectionHandler(hierarchical, searcher.connectFilterState(filterState))
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val view : HierarchicalView = HierarchicalAdapter() // your HierarchicalView implementation
connection += hierarchical.connectView(view, HierarchicalPresenterImpl(separator))
searcher.searchAsync()
}
override fun onDestroy() {
super.onDestroy()
connection.disconnect()
searcher.cancel()
}
}
Low-level API
If you want to fully control the Hierarchical Menu components and connect them manually, use the following components:
Searcher
: TheSearcher
that handles your searches.FilterState
: The current state of the filters.HierarchicalViewModel
: The logic applied to the hierarchical facets.HierarchicalView
: The conrete hierarchical view.HierarchicalPresenter
: The presenter that controls the sorting and other settings of the hierarchical menu.HierarchicalItem
: A single node in the hierarchy.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class MyActivity : AppCompatActivity() {
val client = ClientSearch(
ApplicationID("YourApplicationID"),
APIKey("YourAPIKey")
)
val index = client.initIndex(IndexName("YourIndexName"))
val searcher = SearcherSingleIndex(index)
val filterState = FilterState()
val hierarchicalCategory = Attribute("hierarchicalCategories")
val hierarchicalCategoryLvl0 = Attribute("$hierarchicalCategory.lvl0")
val hierarchicalCategoryLvl1 = Attribute("$hierarchicalCategory.lvl1")
val hierarchicalCategoryLvl2 = Attribute("$hierarchicalCategory.lvl2")
val hierarchicalAttributes = listOf(
hierarchicalCategoryLvl0,
hierarchicalCategoryLvl1,
hierarchicalCategoryLvl2
)
val separator = " > "
val viewModel = HierarchicalViewModel(hierarchicalCategory, hierarchicalAttributes, separator)
val connection = ConnectionHandler()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val view: HierarchicalView = HierarchicalAdapter() // your `HierarchicalView` implementation
connection += searcher.connectFilterState(filterState)
connection += viewModel.connectFilterState(filterState)
connection += viewModel.connectSearcher(searcher)
connection += viewModel.connectView(view, HierarchicalPresenterImpl(separator))
searcher.searchAsync()
}
override fun onDestroy() {
super.onDestroy()
searcher.cancel()
connection.disconnect()
}
}
Parameters
searcher
|
type: SearcherSingleIndex
Required
The |
attribute
|
type: Attribute
Required
The attribute to filter. |
filterState
|
type: FilterState
Required
The |
hierarchicalAttributes
|
type: List<Attribute>
Required
The names of the hierarchical attributes that we need to target, in ascending order. |
separator
|
type: String
Required
The string separating the facets in the hierarchical facets. Usually something like “ > “. Note that you should not forget the spaces in between if there are some in your separator. |
View
view
|
type: HierarchicalView
Required
The view that renders the hierarchical menu. |
||
presenter
|
type: HierarchicalPresenter
Required
How to display the list of |
||
Copy
|