Question
Where can I find a complete example showing how a hierarchical faceted search works from indexing documents to getting search results?
My research so far
Stackoverflow has several messages, but all of them affect only certain aspects of the hierarchical grant search; therefore, I would not duplicate them. I am looking for a complete example to figure this out. I continue to skip the last query in which aggregates work.
There is documentation on the Solr webpage, but did not understand the example given here.
Example (conceptually)
I would like to create a complete example of the passage here and hope you can provide the missing final part.
Testdata h3>
Enter
Say we have 3 documents with each document being a person.
Alice (document 1) - Blond - Europe Jane (document 2) - Brown - Europe/Norway Bob (document 3) - Brown - Europe/Norway - Europe/Sweden
Output
The expected output for this (currently incorrect) request
http://server:8983/solr/my_core/select?q=*%3A*&wt=json&indent=true&facet=true&facet.field=tags_ss
it should be
Hair_color (3) - blond (1) - brown (1) - black (1) Location (3) - Europe (4)
because all documents are found.
Example (software)
I need help here. How to implement the above conceptual example?
That's how far I got.
1. Creating XML test data
This is the contents of the documents.xml file in the subfolder solr-5.1.0/testdata :
<add> <doc> <field name="id">Alice</field> <field name="tags_ss">hair_color/blond</field> <field name="tags_ss">location/Europe</field> </doc> <doc> <field name="id">Jane</field> <field name="tags_ss">hair_color/brown</field> <field name="tags_ss">location/Europe/Norway</field> </doc> <doc> <field name="id">Bob</field> <field name="tags_ss">hair_color/black</field> <field name="tags_ss">location/Europe/Norway</field> <field name="tags_ss">location/Europe/Sweden</field> </doc> </add>
_ss defined in schema.xml as
<dynamicField name="*_ss" type="string" indexed="true" stored="true" multiValued="true"/>
Please note that all tags, for example. hair_color and location , and all tags that will be added in the future, are stored in the same tags_ss field.
2. Test Data Index with Solr
c:\solr-5.1.0>java -classpath dist/solr-core-5.1.0.jar -Dauto=yes -Dc=gettingstarted -Ddata=files -Drecursive=yes -Durl=http://server:8983/solr/my_core/update org.apache.solr.util.SimplePostTool .\testdata

3. Get all the data using the Solr request (without cutting)
Request
http://server:8983/solr/my_core/select?q=*%3A*&wt=json&indent=true
Result
{ "responseHeader": { "status": 0, "QTime": 0, "params": { "indent": "true", "q": "*:*", "_": "1430830360536", "wt": "json" } }, "response": { "numFound": 3, "start": 0, "docs": [ { "id": "Alice", "tags_ss": [ "hair_color/blond", "location/europe" ], "_version_": 1500334369469890600 }, { "id": "Jane", "tags_ss": [ "hair_color/brown", "location/europe/Norway" ], "_version_": 1500334369469890600 }, { "id": "Bob", "tags_ss": [ "hair_color/black", "location/europe/Norway", "location/europe/Sweden" ], "_version_": 1500334369469890600 } ] } }
4. Get all the data using the Solr query (with cut)
Request
http://server:8983/solr/my_core/select?q=*%3A*&wt=json&indent=true&facet=true&facet.field=tags_ss
Result
{ "responseHeader": { "status": 0, "QTime": 0, "params": { "facet": "true", "indent": "true", "q": "*:*", "_": "1430830432389", "facet.field": "tags_ss", "wt": "json" } }, "response": { "numFound": 3, "start": 0, "docs": [ { "id": "Alice", "tags_ss": [ "hair_color/blond", "location/europe" ], "_version_": 1500334369469890600 }, { "id": "Jane", "tags_ss": [ "hair_color/brown", "location/europe/Norway" ], "_version_": 1500334369469890600 }, { "id": "Bob", "tags_ss": [ "hair_color/black", "location/europe/Norway", "location/europe/Sweden" ], "_version_": 1500334369469890600 } ] }, "facet_counts": { "facet_queries": {}, "facet_fields": { "tags_ss": [ "location/europe/Norway", 2, "hair_color/black", 1, "hair_color/blond", 1, "hair_color/brown", 1, "location/europe", 1, "location/europe/Sweden", 1 ] }, "facet_dates": {}, "facet_ranges": {}, "facet_intervals": {}, "facet_heatmaps": {} } }
Pay attention to this section at the bottom of the result:
"facet_fields": { "tags_ss": [ "location/europe/Norway", 2, "hair_color/black", 1, "hair_color/blond", 1, "hair_color/brown", 1, "location/europe", 1, "location/europe/Sweden", 1 ] },
It shows all tags as a flat list (not hierarchical).
5. Get all the data using the Solr query (with hierarchical cut)
Request
Here is my problem. I do not know how to build a query that returns the following result (the result is already shown in the conceptual example above).
Result (dummy, manually created for illustration)
{ "responseHeader":{ "status":0, "QTime":0, "params":{ "facet":"true", "indent":"true", "q":"*:*", "facet.field":"tags_ss", "wt":"json", "rows":"0"}}, "response":{"numFound":3,"start":0,"docs":[] }, "facet_counts":{ "facet_queries":{}, "facet_fields":{ "tags_ss":[ "hair_color,3, // This aggregations is missing "hair_color/black",1, "hair_color/blond",1, "hair_color/brown",1, "location/europe",4, // This aggregation should be 4 but is 1 "location/europe/Norway",2, "location/europe/Sweden",1]}, "facet_dates":{}, "facet_ranges":{}, "facet_intervals":{}, "facet_heatmaps":{}}}
This tag list is still flat, but at least location/europe = 4 will aggregate correctly, but it is not currently. I keep getting location/europe = 1 because it is set only for Alice and Bob Norway and Sweden not aggregated to also count on Europe .
Ideas
- I may need to use
facet.pivot , but I don't know how to do it. - I may need to use
facet.prefix , but I don't know how to do it.
Version