1, to achieve the function
2, the index of the field
3. SOLR Searchhttp://****/collection1/select?q=shop_id:123&rows=1&wt=json&indent=true&facet=true& Facet.pivot=p_type_name,type_name
4. SOLR results
{"Responseheader": {"status": 0, "Qtime": 0, "params": {"facet": "True", "Indent": "true", "Q ":" shop_id:123 "," WT ":" JSON "," Facet.pivot ":" P_type_name,type_name "," Rows ":" 1 "}}," response ": {" Numfou nd ":" "Start": 0, "docs": [{"Add_description": " Natural Whitening Essence Liquid, natural fruit extracts VC ingredient at the same time with green tea antioxidant composition, inhibit melanin production, promote skin collagen synthesis, prevent spot generation, bright white complexion at the same time converge pores, let the skin become clean bright white more tightening to transparent, full of elasticity \ r \ n
\ r \ n "," Type_one ":" 00010 ",
"Brand_Name": "It's skin Thais", "Sug": ["It's skin Thais", "Essence", "Itsskin Thais 10 times times VC Whitening Essence Liquid"], "id": "214", "Share_number": 0, "rank": 0, "Brand_thumb": "Http://n.baai.com/baai/uploadfile/20 15/06/26/201506261520194805.jpg "," Total_num ":", "Discuss_number": 0, "Sales": 4, "p_type_ Name ":" Skin Care "," NamE ":" Itsskin Thais 10 times times VC Whitening Essence Liquid, "name_autocomplete": "Itsskin Thais 10 times times VC Whitening Essence Liquid", "Type_three": "00011", "re Bate ": +," Save_number ": 1," Love_number ": 0," shop_id ": 123," brand_id ": 153," code "
: "000100010000011", "Page_view": 128, "type_id": 404, "Type_parent": "", "Price": 10000,
"Price_c": "10000,USD", "type_name": "Essence", "suggestion": "Itsskin Thais 10 times times VC Whitening Essence Liquid", "p_id": 214,
"Type_two": "0001000100", "thumb": "Http://n.baai.com/baai/uploadfile/2015/07/18/20150718141410960.jpg", "_version_": 1508018604938887168}]}, "facet_counts": {"facet_queries": {}, "Facet_fields": {}, "facet_date
S ': {}, ' Facet_ranges ': {}, ' Facet_pivot ': {' p_type_name,type_name ': [{' field ': ' P_type_name ', "Value": "Skin Care", "Count": "pivot": [{"Field": "Type_name", "value": "Emulsion" , "Count":2}, {"Field": "Type_name", "value": "Make-up Water", "Count": 2}, { "Field": "Type_name", "value": "Eye Cream", "Count": 2}, {"Fiel
D ":" Type_name "," Value ":" Essence "," Count ": 2}, {" Field ":" Type_name ", "Value": "Mask", "Count": 2}, {"Field": "Type_name", "value":
"Face Cream", "Count": 2}, {"Field": "Type_name", "value": "Clean Face", ' Count ': 1}]}, {"Field": "P_type_name", "value": "Makeup", "Count": 2, "pivot": [ {' field ': ' Type_name ', ' value ': ' BB Frost ', ' Count ': 2}]}}}
5, SOLRJ implementation
Public list<searchtype> gettypetree (Integer type,string name) throws solrserverexception{Solrserver Solrserve
R = solrservermanger.getinstance ();
Solrquery squery = new Solrquery ();
List<searchtype> types=new arraylist<searchtype> ();
Squery.setfacet (TRUE); Squery.add ("Facet.pivot", "p_type_name,type_name");
Group Query switch (type) {case 1:squery.setquery ("Name:" +name) based on these two dimensions;
Break
Case 2:squery.setquery ("shop_id:" +name);
Break
Default:sQuery.setQuery ("*:*");
Break
} queryresponse response = Solrserver.query (squery);
namedlist<list<pivotfield>> namedlist = Response.getfacetpivot ();
if (namedlist!= null) {list<pivotfield> pivotlist = null;
for (int i=0;i<namedlist.size (); i++) {pivotlist = Namedlist.getval (i);
if (pivotlist!= null) { for (PivotField pivot:pivotlist) {searchtype typetwo=new searchtype ();
Typetwo.setname (Pivot.getvalue (). toString ());
List<pivotfield> FieldList = Pivot.getpivot ();
if (fieldlist!= null) {list<searchtype> typethrees=new arraylist<searchtype> (); for (PivotField field:fieldlist) {searchtype typethree=n
EW SearchType ();
Typethree.setname (Field.getvalue (). toString ());
Typethrees.add (Typethree);
} typetwo.setsubtypes (Typethrees);
Types.add (Typetwo);
}}} return types; }
6, SOLRJ test code
public static void Main (String [] args) throws solrserverexception{
list<searchtype> Types=gettypetree ( 2, "123");
for (SearchType t:types) {
System.err.println (t.getname () + "===========");
For (SearchType tt:t.getsubtypes ()) {
System.err.println (" ---" +tt.getname ());
}
}
}
7. Test results