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
<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执行的是修改
