【问题标题】:How to achive Autocomplete using solr for nested index?如何使用 solr 实现嵌套索引的自动完成?
【发布时间】:2014-06-26 18:20:29
【问题描述】:

如上是我的索引结构:我想使用solr自动完成获取制造商对应的模型。假设我通过了 applianceCatagory=Boilers、manufacturer=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>

【问题讨论】:

  • 请向我们展示您的 solr 架构
  • 嗨@omu_negru 我已将我的架构代码放在代码的末尾..请看一下..提前谢谢
  • 架构定义看起来不错。也请链接配置文件。我需要查看默认查询字段和查询解析器的类型

标签: solr autocomplete


【解决方案1】:

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

编辑:

model 切换到models_autocomplete 看看是否可行。还可以考虑将默认 qParser 切换为 edismax 并指定多个搜索字段。这当然是假设您的自动请求请求使用 /sugest url

【讨论】:

  • 你能给我一些与 solrConfig 相关的解决方案吗?我删除了额外的“title_autocomplete”。但事情看起来一样:(我需要更改 java 代码吗?
  • 感谢@omu_negru 的回复.. 但仍然尝试相同
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-03
  • 2011-07-19
  • 1970-01-01
  • 1970-01-01
  • 2012-08-23
相关资源
最近更新 更多