r - 如何使用R或PowerShell提取solr查询输出显示的csv输出?

标签 r powershell solr

我正在尝试将数据另存为“csv”格式文件或从类似于以下内容的solr查询中提取为数据框:

http://localhost:8983/solr/techproducts/select?q=ipod&fl=id,cat,name,popularity,price,score&wt=csv

我得到一个作为网页输出的响应,如下所示:
enter image description here

我能够从html文件(网页solr输出)中显示的csv输出中手动复制,粘贴,保存和检索csv格式的数据。但是,我无法使用R来自动化该过程。我既无法通过unlist解析和获取整个内容-按正确的顺序排列输出,也无法提取并将网页中显示的内容另存为csv文件。我徒劳地尝试了solriumhttr软件包。我也尝试在Windows PowerShell中使用Export-Csv选项将数据保存为csv文件格式,但没有任何运气。

请求建议以解决该问题。

最佳答案

这没有解决有关powershell的任何特定问题,但是首先使用solrium可以做到这一点,如果没有解决,它怎么会失败:

(要完全复制),设置Solr

cd solr-6.6.0
bin/solr start -e cloud -noprompt
bin/solr create -c techproducts -d sample_techproducts_configs
bin/post -c techproducts example/exampledocs/*.xml 

在R中:
solr_connect()
(df <- solr_search(
        name = "techproducts", 
        q = "ipod", 
        fl = c("id", "cat", "name", "popularity", "price", "score"), 
        wt = "csv"))
#> # A tibble: 3 x 6
#>                id                   cat                                       name popularity  price     score
#> *           <chr>                 <chr>                                      <chr>      <int>  <dbl>     <dbl>
#> 1           IW-02 electronics,connector             iPod & iPod Mini USB 2.0 Cable          1  11.50 3.2388113
#> 2 F8V7067-APL-KIT electronics,connector  Belkin Mobile Power Cord for iPod w/ Dock          1  19.95 2.3162508
#> 3       MA147LL/A     electronics,music Apple 60 GB iPod with Video Playback Black         10 399.00 0.9044058

write.csv(df, "myfile.csv", row.names = FALSE)

readLines("myfile.csv")
#> [1] "\"id\",\"cat\",\"name\",\"popularity\",\"price\",\"score\""                                                   
#> [2] "\"IW-02\",\"electronics,connector\",\"iPod & iPod Mini USB 2.0 Cable\",1,11.5,3.2388113"                      
#> [3] "\"F8V7067-APL-KIT\",\"electronics,connector\",\"Belkin Mobile Power Cord for iPod w/ Dock\",1,19.95,2.3162508"
#> [4] "\"MA147LL/A\",\"electronics,music\",\"Apple 60 GB iPod with Video Playback Black\",10,399,0.9044058"  

关于r - 如何使用R或PowerShell提取solr查询输出显示的csv输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45555009/

相关文章:

r - ggplot map - 使用 coord_map 时出现不需要的水平线

windows - PowerShell 将 AD objectGUID 复制到 ms-ds-consistencyguid

function - Powershell - 如何构建一个函数来用其他字符替换某些特殊字符

powershell - 运行powershell脚本时 '>>'是什么?

mysql - Solr - 匹配逗号分隔的 ID

dynamic - Solr 在结果中为每个文档返回不同的输出字段

pmax 函数输出的返回属性

r - 如何使geom_line和geom_point抖动相同的幅度?

r - 在分组的时间序列中填充缺失的日期-tidyverse方法?

Solr 将 CommonsHttpSolrServer 更改为 HttpSolrServer