Hi Rashmi,
Here is some more details on how to use PathHierarchyTokenizer that Oleg
provided the link to.
If this is your document:
*Sample document*
doc
name=Pbook1
category=NonFic/Sci/Phy/Quantum
author=ABC
price=20.00
doc
Then, in your schema.xml:
field name=category type=tree indexed=true stored=true
multiValued=true/
fieldType name=tree class=solr.TextField
analyzer type=index
tokenizer class=solr.PathHierarchyTokenizerFactory delimiter=/ /
/analyzer
analyzer type=query
tokenizer class=solr.KeywordTokenizerFactory /
/analyzer
/fieldType
Then, in your Solr query, you can simply add:
facet=true
facet.field=category
You should see a facet that contains each level of the taxonomy with counts.
To navigate the taxonomy you add filter queries using the part of the path
you want narrow the results down to (values from the category facet).
So, for example a user clicks on NonFic
facet=true
facet.field=category
fq={!term f=category}NonFic
Then NonFic/Sci
fq={!term f=category}NonFic/Sci
Then NonFic/Sci/Phy
fq={!term f=category}NonFic/Sci/Phy
etc..
If you only want to display the leaf level category and indent child
categories you can easily do this in your UI by splitting the facet value
on your separator, / in this case.
Thanks,
Evan
On Nov 14, 2014 8:06 PM, Oleg Savrasov osavra...@griddynamics.com wrote:
Hi Rashmi,
I believe you are looking for PathHierarchyTokenizer,
see
https://lucene.apache.org/core/4_0_0/analyzers-common/org/apache/lucene/analysis/path/PathHierarchyTokenizer.html
Oleg
2014-11-14 17:53 GMT-05:00 rashmy1 rashmy.appanerava...@siemens.com:
Hello,
I'm trying to setup Solr for fetching hierarchical facets.
Please advice which of the below approaches should be followed for my
scenario.
*Scenario:
*
NonFic
Hist
HistBook1
HistBook2
Sci
Phy
Quantum
Pbook1
Pbook2
Thermodynamics
Pbook3
Pbook4
Chem
Cbook1
Math
Mbook1
Fic
Mystery
Mybook1
Childrens
Chbook1
Chbook2
*Sample document*
doc
name=Pbook1
category=NonFic/Sci/Phy/Quantum
author=ABC
price=20.00
doc
*Requirements:*
-Show drill down facets
-If user searched for *, the initial set of facets to be shown are
'NonFic' and 'Fic'
-If user selects facet 'NonFic', we then show the facets 'Hist' and 'Sci'
only.
*Option1:*
/Solr schema:/
field indexed=true multiValued=true name=category required=true
stored=true type=string/
/Document supplied for indexing:/
doc
name=Pbook1
category=0/NonFic
category=1/NonFic/Sci
category=2/NonFic/Sci/Phy
category=3/NonFic/Sci/Phy/Quantum
category=0/Other (a book can belong to multiple categories)
author=ABC
price=20.00
doc
With Option2, we can do a drill down facet query.
For example, if we give facet.prefix=NonFic/Sci/, the facet results are:
NonFic/Sci/Phy
NonFic/Sci/Chem
NonFic/Sci/Math
The only issue is that I have to take care of generating all possible
path
information for 'category'
*Option2:*
/Solr schema:/
fieldType class=solr.TextField name=path
analyzer type=index
tokenizer class=solr.PathHierarchyTokenizerFactory
delimiter=//
/analyzer
/fieldType
field indexed=true multiValued=true name=category required=true
stored=true type=path/
/Document supplied for indexing:/
doc
name=Pbook1
category=NonFic/Sci/Phy/Quantum
author=ABC
price=20.00
doc
With Option2, we can do facet query but it returns all possible
combination
of paths.
For example, if we give facet.prefix=Fic, the facet results are:
Fic (3)
Fic/Mystery (1)
Fic/Childrens (2)
I'm looking to supply a doc with just a single entry (like
'category=NonFic/Sci/Phy/Quantum' ) and be able to do a drill down query.
Is
there some existing Solr tokernizer which takes care of generating all
possibly combinations which indexing instead of having to generating them
as
part of doc creation?
Thanks
--
View this message in context:
http://lucene.472066.n3.nabble.com/Hierarchical-faceting-tp4169263.html
Sent from the Solr - User mailing list archive at Nabble.com.