【第二章】用solr 4.4 创建索引
solr吧
全部回复
仅看楼主
level 9
no.1 solr服务的 schema.xml 文件增加索引的字段
<field name="msg_content" type="text_general" indexed="true" stored="true"/> <field name="msg_date" type="date" indexed="true" stored="true"/> <field name="msg_pid" type="string" indexed="true" stored="true"/> <field name="msg_id" type="string" indexed="true" stored="true"/> <field name="msg_title" type="text_general" indexed="true" stored="true"/> <field name="msg_type" type="text_general" indexed="true" stored="true"/>
no.2 添加索引的测试文件
package data;
import java.io.IOException;import java.util.ArrayList;import java.util.List;
import org.apache.solr.client.solrj.SolrServer;import org.apache.solr.client.solrj.SolrServerException;import org.apache.solr.client.solrj.impl.HttpSolrServer;import org.apache.solr.common.SolrInputDocument;
public class Test {private final static String URL = "http://localhost:1234/solr";private static SolrServer server;
/** * @param args */public static void main(String[] args) {server = new HttpSolrServer(URL);test02();}public static void test02() { try { List<SolrInputDocument> docs = new ArrayList<SolrInputDocument>(); SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", "7"); doc.addField("msg_title", "很好!solr可以工作了"); doc.addField("msg_content", "slor总算可以正式工作了"); docs.add(doc); doc = new SolrInputDocument(); doc.addField("id", "8"); doc.addField("msg_title", "<p>测试一下solr的添加</p>"); doc.addField("msg_content", "看看能不能添加一个列表信息"); docs.add(doc); server.add(docs); server.commit(); } catch (SolrServerException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
}
no.3 用solr服务查看 http://localhost:1234/solr/#/collection1/query 果,注意 如果创建的 索引 id 一样的话 solr执行的是修改
2013年08月21日 08点08分 1
level 9
我擦 帖子 回复 之后 成这样了 看博客吧 http://360193550.iteye.com/blog/1928355 solr简单 操作
2013年08月21日 11点08分 2
能请教一下对文件的索引吗?比如pdf的索引过程,wiki上的明显不行啊
2014年09月20日 02点09分
回复 yturg : 对文件 索引 读取 内容 建立索引 不就得了
2014年09月20日 06点09分
那还能叫全文索引吗......
2014年09月20日 10点09分
我已经搞定了
2014年09月20日 10点09分
level 9
2013年08月22日 00点08分 3
level 9
水一下
2013年08月22日 08点08分 4
level 9
水一下
2013年08月24日 01点08分 5
1