【问题标题】:Can you pass softcommit on update URL to SOLR?您可以将更新 URL 上的软提交传递给 SOLR 吗?
【发布时间】:2013-12-18 19:56:12
【问题描述】:

我想通过软提交向 solr 发送更新。

类似这样的:

http://xxx:8983/solr/corename/update?softcommit=true

我正在使用 C#,所以代码如下所示:

public void PostToSolr( string solrXML, SolrCommitType commitType )
    {
        string uri = solrConfig.UpdateURL;  //something like  "http://xxxx:8983/solr/corename/update";

        switch( commitType )
        {
            case SolrCommitType.SOFT:
                uri = uri + "?softcommit=true";
                break;

            case SolrCommitType.HARD:
                uri = uri + "?commit=true";
                break;
        }

        HttpWebResponse response = null;
        WebRequest request = WebRequest.Create( uri );

        try
        {

            request.ContentType = "application/xml";
            request.Method = "POST";
            using( var rs = request.GetRequestStream( ) )
            {
                byte[] byteArray = Encoding.UTF8.GetBytes( solrXML );
                rs.Write( byteArray, 0, byteArray.Length );
            }

            // get response
            response = request.GetResponse( ) as HttpWebResponse;

            HttpStatusCode statusCode = response.StatusCode;

            if( statusCode != HttpStatusCode.OK )
            {
                throw new Exception( String.Format( "HttpStatusCode={0}.", statusCode.ToString( ) ) );
            }
        }
        catch( Exception ex )
        {
            throw new Exception( String.Format( "Uri={0}. Post Data={1}", uri, solrXML ), ex );
        }
        finally
        {
            if( null != response )
            {
                response.Close( );
                response = null;
            }

            request = null;
        }
    }

当我通过软提交发布到 SOLR 时,更新的文档不会立即可见。在 solr 配置中,我已将 autosoftcommit 设置为每分钟发生一次,因此最终更新的文档确实变得可见。

如何通过更新发送新文档并使其立即可见而无需提交并重新打开搜索器?有没有办法强制软提交?还是软提交仅根据配置文件中设置的策略发生?

【问题讨论】:

  • 建议查看 SolrNet 客户端 - github.com/mausch/SolrNet 您可以使用可在执行软提交的添加期间发送的 commitWithin 参数。

标签: c# solr solr4


【解决方案1】:

您需要做的就是使用参数softCommit(驼峰式),这样就可以解决问题。示例请求是:

curl http://localhost:8983/solr/collection1/update?softCommit=true -H "Content-Type: text/xml" --data-binary '<add><doc><field name="id">testdoc2</field></doc></add>'

它可以在添加文档后使用,以提交您尝试过的尚未提交的内容,但使用驼峰式 softCommit 布尔参数。

来自documentation

softCommit = "true" | "false" - 默认为 false - 执行软提交 - 这将以更高性能的方式刷新索引的“视图”,但没有“磁盘上”保证。 Solr (!) 4.0

【讨论】:

  • 这很容易。 +1 用于远程结对编程。
猜你喜欢
  • 2011-12-20
  • 2017-09-17
  • 2013-01-20
  • 1970-01-01
  • 2020-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-28
相关资源
最近更新 更多