Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 能否将更新URL上的softcommit传递给SOLR?_C#_Solr_Solr4 - Fatal编程技术网

C# 能否将更新URL上的softcommit传递给SOLR?

C# 能否将更新URL上的softcommit传递给SOLR?,c#,solr,solr4,C#,Solr,Solr4,我想用softcommit向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

我想用softcommit向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;
        }
    }
当我使用softcommit发布到SOLR时,更新的文档不会立即可见。在solr配置中,我将autosoftcommit设置为每分钟发生一次,因此最终更新的文档确实变得可见


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

您只需使用参数
softCommit
(驼峰式),这将解决问题。一个示例请求是:

curlhttp://localhost:8983/solr/collection1/update?softCommit=true -H“内容类型:text/xml”--数据二进制:

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


那很容易+1用于远程配对编程。建议查看SolrNet客户端-您可以使用commitWithin参数,该参数可以在执行软提交的adds期间发送。