一.搭建solr服务(standalone)很简单,三步解决
1.下载solr-5.3.1.tgz,解压文件
2.在./solr-5.3.1/server/solr目录下建个文件夹作为存放core的地方
3.将./solr-5.3.1/server/solr/configsets/sample_techproducts_configs/下的conf拷到第二步建的文件夹下面
启动solr就可以了......
二.solr配置文件schame.xml学习
1.field
name: mandatory - the name for the field
type: mandatory - the name of a field type from the <types> fieldType section
indexed: true if this field should be indexed (searchable or sortable)
stored: true if this field should be retrievable
docValues: true if this field should have doc values. Doc values are useful for faceting, grouping,
sorting and function queries. Although not required, doc values will make the index
faster to load, more NRT-friendly and more memory-efficient. They however come with some
limitations: they are currently only supported by StrField, UUIDField and all Trie*Fields,
and depending on the field type, they might require the field to be single-valued, be
required or have a default value (check the documentation of the field type you‘re interested in
for more information)
multiValued: true if this field may contain multiple values per document
omitNorms: (expert) set to true to omit the norms associated with this field (this disables length
normalization and index-time boosting for the field, and saves some memory). Only full-text
fields or fields that need an index-time boost need norms. Norms are omitted for primitive
(non-analyzed) types by default.
termVectors: [false] set to true to store the term vector for a given field. When using MoreLikeThis,
fields used for similarity should be stored for best performance.
termPositions: Store position information with the term vector.This will increase storage costs.
termOffsets: Store offset information with the term vector. This will increase storage costs.
termPayloads: Store payload information with the term vector. This will increase storage costs.
required: The field is required. It will throw an error if the value does not exist
default: a value that should be used if no value is specified when adding a document.
2.优化
PERFORMANCE NOTE: this schema includes many optional features and should not be used for benchmarking.
To improve performance one could
- set stored="false" for all fields possible (esp large fields) when you only need to search on the
field but don‘t need to return the original value.
- set indexed="false" if you don‘t need to search on the field, but only return the field as a result
of searching on other indexed fields.
- remove all unneeded copyField statements
- for best index size and searching performance, set "index" to false for all general text fields,
use copyField to copy them to the catchall "text" field, and use that for searching.
- For maximum indexing performance, use the ConcurrentUpdateSolrServer java client.
- Remember to run the JVM in server mode, and use a higher logging level that avoids logging every request
三.JAVA api简单使用
public class App{
private static SolrClient client = null;
static{
client = new HttpSolrClient("http://192.168.40.129:8983/solr/collection1");
}
public void add() throws Exception{
SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", "107");
doc.setField("email_box_title", "107hehehe");
client.add(doc);
client.commit();
}
public void remove() throws Exception {
client.deleteById("106");
client.commit();
}
public void query() throws Exception {
QueryResponse resp = client.query(new SolrQuery("id:10*"));
SolrDocumentList doclist = resp.getResults();
for(SolrDocument doc : doclist){
System.out.println(doc.getFieldValue("id")+":"+doc.getFieldValue("email_box_title"));
}
}
public static void main( String[] args ) throws Exception {
App app = new App();
app.add();
app.query();
}
}