2011-10-28 31 views
12

我需要驗證文本提取是否適用於Windows Server 2003上的Solr安裝。我發現的用於將文件上傳到Solr的所有示例都使用如下所示的curl。如何將文件上傳到Windows中的Solr?

curl "http://localhost:8983/solr/update/extract?&extractOnly=true" --data-binary @tutorial.html -H 'Content-type:text/html' 

如何在Windows中執行此操作?我想測試上傳pdf和Word文檔,然後確認我可以使用Solr管理頁面搜索包含在文檔中的單詞。

回答

17

通過例子來一個post.jar(見apache-solr-X.X.X.zip的文件夾example\exampledocs):

java -jar post.jar -h

This is a simple command line tool for POSTing raw data to a Solr 
port. Data can be read from files specified as commandline args, 
as raw commandline arg strings, or via STDIN. 
Examples: 
    java -jar post.jar *.xml 
    java -Ddata=args -jar post.jar '<delete><id>42</id></delete>' 
    java -Ddata=stdin -jar post.jar < hd.xml 
    java -Durl=http://localhost:8983/solr/update/csv -Dtype=text/csv -jar post.jar *.csv 
    java -Durl=http://localhost:8983/solr/update/json -Dtype=application/json -jar post.jar *.json 
    java -Durl=http://localhost:8983/solr/update/extract?literal.id=a -Dtype=application/pdf -jar post.jar a.pdf 
Other options controlled by System Properties include the Solr 
URL to POST to, the Content-Type of the data, whether a commit 
or optimize should be executed, and whether the response should 
be written to STDOUT. These are the defaults for all System Properties: 
    -Ddata=files 
    -Dtype=application/xml 
    -Durl=http://localhost:8983/solr/update 
    -Dcommit=yes 
    -Doptimize=no 
    -Dout=no 

OR

在Windows PowerShell 3.0具有Invoke-WebRequest命令,它肯定可以使用爲了那個原因。見this blog post

Invoke-WebRequest

+0

我試圖用post.jar張貼的PDF,但我得到一個錯誤。 SimplePostTool:致命:Solr返回錯誤#405方法不允許。 – John81

+0

@John:你可以發表你正在使用的命令嗎? – jeha

+1

@John:我剛剛嘗試過使用標準示例:通過'apache-solr-3.4.0 \ example> java -jar start.jar'啓動服務器,並將該文件發佈爲'apache-solr-3.4.0 \ example \ exampledocs> java -Durl = http:// localhost:8983/solr/update/extract?literal.id = foobar -Dtype = application/pdf -jar post.jar foobar.pdf'適合我... – jeha

1

可以有以下選擇 - 使用指向本地文件系統上的文件的stream.file(stream.url遠程URL)的參數從瀏覽器

  • 消防網址,例如: sample_url
  • 安裝windows的cgywin/curl,它可以幫助你啓動這些網址。
  • 寫一個簡短的program using Solrj(或任何其他solr客戶端)發佈這些文件。
+0

有一點補充:CURL可用於Windows。還有libCURL,它允許您將CURL操作嵌入到數十種主要語言中。 – aitchnyu

1

您可以嘗試使用Firefox的插件海報。我試過幾個下載的,他們工作得很好:)

1

你可以試試這個:

C:\的Java \利布斯\ apache- solr-4.0.0-BETA \ example>「C:\ Program Files(x86)\ Internet Explorer \ iexplore.exe」「http:// localhost:8983/solr/collection1/update?commit = true & stream.contentType = text/csv; charset = utf-8 & stream.file = C:/Java/Libs/apache-solr-4.0.0-BETA/example/exampledocs/listado_talleres_new.csv「

+0

你似乎過分地對系統做出了假設。你可以編輯你的答案是更普遍適用? - 你也沒有指定你的答案應該做什麼,你能否至少添加一個簡短的解釋? –

1

如果要使用cURL命令將文件發佈到solr,您需要從cURL Home下載此實用程序。在路徑environmental variable of the windows提供cURL.exe的路徑,然後可以用你用於查詢

curl "http://localhost:8983/solr/update/extract?&extractOnly=true" --data-binary @"location of file/test.pdf" -H 'Content-type:application/pdf' 

即你必須更改內容類型的命令。

將目錄發佈到Solr的另一種方法是在Solr的examples目錄中使用'post.jar'實用程序 - 請記住該實用程序不適用於生產用途。

下面是示例命令。完全符合Solr的4.0

2

使用Solr 5.0

java -Ddata=files -Dtype=html -Dfiletypes=htm,html -Dauto=yes -Drecursive=yes -jar post.jar "Drive_letter:\yourpath\." 

上述工作就不得不提到核心的名字在更新文檔。所以張貼在exampledocs所有實例的命令是:

的Java -DC = 「core_name」 罐子post.jar的* .xml

這裏核心的名稱替換core_name

1

在Windows上使用Solr的6.1,我能夠遞歸指數使用SimplePostTool從Solr的核心 - xyzjar像這樣的文件夾:

java -classpath C:\Solr\solr-6.1.0\dist\solr-core-6.1.0.jar -Dauto=yes -Dc=yourcorename -Ddata=files -Drecursive=yes org.apache.solr.util.SimplePostTool C:\Solr\solr-6.1.0\docs 

您需要repla使用solr文件夾將ce「C:\ Solr \ solr-6.1.0 \」指定爲solr-core-6.1.0.jar的正確版本號,將該文件夾設置爲要索引的文件位置並確保核心已經存在。

0

對於Windows我用這個cоmmand:

java -classpath %SOLR_HOME%\dist\solr-core-6.5.1.jar -Dauto=yes -Dc=books -Ddata=files -Drecursive=yes org.apache.solr.util.SimplePostTool c:\apache-solr-6.5.1\server\solr\books\data\index\*.* 
0

爲了做到這一點使用PowerShell中運行以下命令:

$header = @{"Content-type"="text/plain"; "charset"="utf-8"}; 

Invoke-WebRequest -Uri http://localhost:8983/solr/YOUR_CORE_NAME/update/csv -Headers $header -InFile "C:\data.csv" -Method Post 
相關問題