如何获取SOLR文档的字数?

s2j5cfk0  于 2022-11-05  发布在  Solr
关注(0)|答案(1)|浏览(168)

我有一个pdf文件的二进制内容,我想将其上传到SOLR并为其内容编制索引:

ContentStreamUpdateRequest up = new ContentStreamUpdateRequest('/update/extract')
    up.setParam("literal.id", map.id)
    def tmpFile = null
    tmpFile = File.createTempFile(map.id, ".tmp")
    tmpFile.append(binary)
    up.addFile(tmpFile, ".pdf")
    // Do the SOLR stuff here
    def solr = getSolrServer()       
    up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true)
    def response = solr.request(up)
    if (tmpFile) {
        tmpFile.delete()
    }
    return response

当我查询SOLR时,我可以检索SOLR文档。我如何才能得到文件的实际内容呢?基本上我需要找到我上传的文档的字数,所以我打算对返回的字符串执行size()(如果可能的话)......
我对SOLR很陌生,所以我可能走错了路......任何帮助都非常感谢:)

wnavrhmk

wnavrhmk1#

我假设你想计算你索引的PDF中的字数。

  1. PDF的整个提取内容将编入一个字段的索引。
    1.请确保此字段至少启用了一个空格标记器。以便它根据空格将句子拆分为单词。
    一旦你这样做,你可以找到的话,无论是使用方面或术语向量分量。下面的SO答案可能会有帮助:
    https://stackoverflow.com/a/26933126/689625

相关问题