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
如何将文件从数据库加载到Solr中_Solr_Solrj - Fatal编程技术网

如何将文件从数据库加载到Solr中

如何将文件从数据库加载到Solr中,solr,solrj,Solr,Solrj,我使用下面的Groovy代码加载存储在MongoDB中的文件,以便在Solr中编制索引。(我已经创建了一个包含文件内容和文件名的文件对象): 所以,我已经有了一个文件的字节数组,但我正在将其写入磁盘,以便使用addFile方法。然后,作为清理,我删除磁盘上的文件。这很有效,但很愚蠢 我尝试用以下代码代替up.addFile(),但它抛出了一个“非ok状态:500消息:服务器错误” 在不需要将文件写入磁盘作为中间步骤的情况下,为内存中已有的文件编制索引的最佳方法是什么?您可以检查允许使用流的方法

我使用下面的Groovy代码加载存储在MongoDB中的文件,以便在Solr中编制索引。(我已经创建了一个包含文件内容和文件名的文件对象):

所以,我已经有了一个文件的字节数组,但我正在将其写入磁盘,以便使用addFile方法。然后,作为清理,我删除磁盘上的文件。这很有效,但很愚蠢

我尝试用以下代码代替up.addFile(),但它抛出了一个“非ok状态:500消息:服务器错误”

在不需要将文件写入磁盘作为中间步骤的情况下,为内存中已有的文件编制索引的最佳方法是什么?

您可以检查允许使用流的方法

此外,如果您有一个web界面来公开该文件,则可以进行检查

ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update/extract")

def tempFile = new File("temp/temp-${file.name}")
tempFile.append(file.file) //file.file references the byte[] of the file
//append call writes the file to disk

up.addFile(tempFile, "application/octet-stream")

up.setParam("literal.id", file.id.toString())
up.setParam("literal.name", "ConsultantFile")
up.setParam("literal.fileName_s", file.name)
up.setParam("literal.creator_s", file.createdBy?.lastFirstName)

up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true)

server.request(up) //server object is the shared handle to the Solr instance

tempFile.delete()
def stringFile = new String(file.file, "UTF-8")
def stream = new ContentStreamBase.StringStream(stringFile)
up.addContentStream(stream)