5

在 Solr 中,如果我们在 schema 中有一个字段为 stored="true",并且我们更改了与该字段关联的分析器,是否可以只更新该字段而不重新索引所有文档?这是否可以在不返回原始数据源的情况下使用新分析器的字段“存储”值来完成?

4

3 回答 3

1

伙计,我优化了你的代码。

    ...
    while (iter.hasNext()) {
        ...
        //server.deleteById(id) ;
        //server.commit() ;

        Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
        docs.add(inputdoc) ;
        server.add(docs) ;
        // server.commit() ;
    }
    server.commit() ;
于 2010-12-03T09:48:36.310 回答
0

我找到了一种使用 SolrJ 的方法。

        SolrQuery query = new SolrQuery();

        query.setQuery( "whatever_by_id" );

        QueryResponse rsp;

        rsp = server.query(query);

        Iterator<SolrDocument> iter = rsp.getResults().iterator();

        while (iter.hasNext()) {
            SolrDocument resultDoc = iter.next();
            String id = (String) resultDoc.getFieldValue("oid"); //id is the uniqueKey field

            SolrInputDocument inputdoc = new SolrInputDocument() ;
            for( Map.Entry<String, Object> f : resultDoc.entrySet()) {
                inputdoc.setField(f.getKey(), f.getValue()) ;
            }

            server.deleteById(id) ;
            server.commit() ;

            Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
            docs.add(inputdoc) ;
            server.add(docs) ;

            server.commit() ;
        }

当我们添加“新”输入文档(旧 resultDoc 的副本)时,它使用我们在模式中更改的新分析器来索引。它不是很优雅,但它确实有效。

于 2010-10-27T22:29:22.517 回答
0

查看IBM Solr 教程

于 2010-12-24T18:40:17.887 回答