ApacheSolr中的索引是什么?
我可以将pdf文件上传到ApacheSolr中的索引是什么?,solr,lucene,Solr,Lucene,我可以将pdf文件上传到solr中,并可以搜索这些文件。但是什么是solr中的索引?当我上传pdf文件时,它将如何进行索引 这是我用来上传pdf文件的代码 ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update/extract"); up.addFile(fileName); up.setParam("literal.id", so
solr
中,并可以搜索这些文件。但是什么是solr
中的索引?当我上传pdf文件时,它将如何进行索引
这是我用来上传pdf文件的代码
ContentStreamUpdateRequest up
= new ContentStreamUpdateRequest("/update/extract");
up.addFile(fileName);
up.setParam("literal.id", solrId);
up.setParam("literal.first_name", "apachesolr");
up.setParam("literal.last_name", "cookbook");
up.setParam("literal.age", "30");
up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
solrServer.request(up);
下面是我的schema.xml
<field name="first_name" type="string" indexed="true" stored="true" required="true"/>
<field name="last_name" type="string" indexed="true" stored="true" required="true"/>
<field name="age" type="int" indexed="true" stored="true" required="true"/>
<field name="created_at" type="date" indexed="true" stored="true"/>
<field name="updated_at" type="date" indexed="true" stored="true"/>
<field name="id" type="string" indexed="true" stored="true" required="true"/>
它将如何能够获得标题,作者,关键字。。。等等?您误解了搜索引擎中文档的概念文档是一组具有相应值的命名字段。您应该始终明确设置每个字段。首先,使用Solrj尝试以下代码:
CommonsHttpSolrServer solr = new CommonsHttpSolrServer("http://localhost:8983/solr");
for(int i = 0; i < 1000; ++i) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("title", "My Favorite book");
doc.addField("author", "Kevin");
doc.addField("content", "Bla bla bla");
solr.add(doc);
}
solr.commit();
CommonHttpSolrServer solr=新的CommonHttpSolrServer(“http://localhost:8983/solr");
对于(int i=0;i<1000;++i){
SolrInputDocument doc=新的SolrInputDocument();
addField博士(“书名”,“我最喜欢的书”);
addField博士(“作者”、“凯文”);
文件addField(“内容”,“布拉布拉布拉布拉布拉布拉布拉”);
解决方案添加(文档);
}
solr.commit();
此代码创建新的SolrInputDocument
并添加3个字段-“标题”、“作者”和“内容”(注意:所有这些字段都应该在schema.xml中定义,以便让Solr知道如何索引和存储这些字段),然后将新文档添加到事务中(Solr.add(doc)
),最后提交更改。这是使用Solr的基本方法
在此正常流程中,您应该从文档中提取文本。例如,您可以为此目的使用。这是最灵活和细粒度的方法
您试图做的是使用新的Solr功能-内容提取。如果我理解正确,您试图用setParams()
设置字段,这是错误的setParams()
只设置请求参数,然后将这些参数转换为URL参数,让Solr知道如何处理请求本身。据我所知,这样你就不能自己设置字段了。相反,/update/extract
处理程序将尝试按文件的MIME类型提取内容,查找有关文档属性的提示,并将其用作字段(注意,Solr使用Tika库提取文档内容)。因此,如果您真的想使用/update/extract
处理程序,请尝试遵循而不更改与请求参数对应的行,并检查生成的字段
CommonsHttpSolrServer solr = new CommonsHttpSolrServer("http://localhost:8983/solr");
for(int i = 0; i < 1000; ++i) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("title", "My Favorite book");
doc.addField("author", "Kevin");
doc.addField("content", "Bla bla bla");
solr.add(doc);
}
solr.commit();