如何使用solr实现嵌套索引的自动完成?

时间:2014-06-26 18:20:29

标签: solr autocomplete

以上是我的索引结构:我想使用solr auto complete获取制造商相应的模型。假设我将applianceCatagory = Boilers,manufacture = ariston和查询字符串传递给" cla"然后所有与ariston制造相对应的模型都应该显示..我做了一些java编码来获取下面给出的值:但我只能获取以小写字符开头的模型,如果我传递小写查询字符串并且相同对于大写:请帮助!!谢谢你的语气。

 <i>{
        "manuals": [
            {
                "applianceCategory": "Boilers",
                {
                        "manufacturer": "Ariston",
                        {
                            "models": [
                                        "CLAS HE 24 evo",
                                        "CLAS HE 30 evo",
                                        "LAP HE System 24 evo",
                                        "LAST HE System 30 evo"
                                        "clas HE",
                                        "cLAS ba",
                                        ],
                        }
                        "manufacturer": "Baxi",
                        {
                            "models": [
                                        "Baxi 1",
                                        "Baxi 2",
                                        "CLAS 3"
                                        ],
                        }

               },
            }
            {
                "applianceCategory": "Electrics",
                {
                        "manufacturer": "Lipton",
                        {
                            "models": [
                                        "PLAS HE",
                                        "PLAS HE 30",
                                        "PLAS HE 38 evo",
                                        "PLAS HE Sm 18 evo",
                                        "PLAS HEm 24 evo",
                                        "PLAS HE Syst"
                                        ],
                        }

               },
            }
        ]
    }

    Java Code:
    private static void getModelValues(SolrServer server,String queryString) throws SolrServerException{
            SolrQuery query = new SolrQuery();

            query.setParam("wt", "json");
            query.setQuery("Boilers").setQuery("Ariston");
            query.setFacet(true);
            query.addFacetField("models");
            query.setFacetMinCount(1);
            query.setFacetPrefix(queryString);

            QueryResponse response = server.query(query);
            List<FacetField> facetField = response.getFacetFields();
            List<String> listofModel=null;
                 for (int j = 0; j < facetField.size(); j++) {
                      listofModel = new ArrayList<String>();
                     for(Count count: facetField.get(j).getValues()){
                         listofModel.add(count.getName());
                     }
                     System.out.println("This is the model list---->"+listofModel);
                    Gson gson1 = new Gson();
                    System.out.println("Models:"+gson1.toJson(listofModel));
                 }  


        }

 <field name="manufacturer" type="string" indexed="true" stored="true" required="true" multiValued="true" docValues="true" /> 
     <field name="models" type="string" indexed="true" stored="true" termVectors="true" termPositions="true" termOffsets="true" required="true" multiValued="true" docValues="true" /> 
     <field name="applianceCategory" type="string" indexed="true" stored="true" required="true" multiValued="true" docValues="true" /> 
     <field name="manual" type="string" indexed="true" stored="true" required="true" multiValued="false" docValues="true" /> 
     <field name="models_autocomplete" type="text_autocomplete" indexed="true" stored="true" multiValued="true"/>

<!--Copy field -->   
     <copyField source="manufacturer" dest="text"/>
<copyField source="models" dest="models_autocomplete"/>
<copyField source="applianceCategory" dest="text"/>
<copyField source="manual" dest="text" /> 
    </i>

1 个答案:

答案 0 :(得分:0)

您的/sugest SearchHandler定义了"spellcheck.dictionary"两次:一次用于title_autocomplete字段,一次用于models字段。除了我不知道solr在指定两次相同的键时表现如何,我没有在配置中的任何地方看到models_autocomplete字段,所以你的默认搜索或你的sugest组件都没有使用它字典来查询它。

编辑:

model切换为models_autocomplete并查看是否有效。还可以考虑将默认qParser切换为edismax并指定多个搜索字段。当然,假设您的自动提取请求使用/sugest网址