Solr Notes All In One


Update CSV
http://wiki.apache.org/solr/UpdateCSV
/solr/update/csv?stream.file=file_path&separator=,&fieldnames=a_list&f.accesstime.map=0:&f.ctime_tdt.map=0:&f.mtm.map=0&skip=type&literal.type=type1
curl http://localhost:8983/solr/update/csv --data-binary @books.csv -H 'Content-type:text/plain; charset=utf-8'
SoftCommit
http://localhost:8080/solr/update?commit=true&softCommit=true
Update Data Via XML
Add Data
http://mailsearchsolr:8765/solr/update?commit=true&stream.body=<add><doc><field name="id">testdoc</field></doc></add>
Delete Data
host:post/solr/update?stream.body=<delete><query>*:*</query></delete>&commit=true
Set Proxy
When used with http monitor tools like fiddle, use -x to set proxy
curl -x localhost:8888 -X PUT -H Content-Type:application/json -d {\"type\":\"string\",\"stored\":\"false\",\"indexed\":\"true\"} "http://host:port/solr/schema/fields/newfield2"
About how to use Curl to import data to Solr, read Learning Solr Code: Import Data to Solr
-- Especailly how to add " or escape ".
View Source code of file
http://localhost:8080/solr/admin/file/?contentType=text/xml;charset=utf-8&file=schema.xml
SignatureUpdateProcessorFactory to generate unqiue string
<processor class="solr.processor.SignatureUpdateProcessorFactory">
 <bool name="enabled">true</bool>
 <str name="signatureField">id</str>
 <bool name="overwriteDupes">false</bool>
 <str name="fields">fields</str>
 <str name="signatureClass">solr.processor.Lookup3Signature</str>
</processor>
BKDRHash
public long BKDRHash(String str)
{
  long seed = 131; // 31 131 1313 13131 131313 etc..
  long hash = 0;
  for(int i = 0; i < str.length(); i++)
  {
     hash = (hash * seed) + str.charAt(i);
  }
  return (hash & 0x7FFFFFFF);
}
Analyzer and Filter
ReversedWildcardFilterFactory
Use this to support leading wildcard and prefix queries.
<filter class="solr.ReversedWildcardFilterFactory" withOriginal="true" maxPosAsterisk="3" maxPosQuestion="2" maxFractionAsterisk="0.33"/>
Code
Change NamedList to SolrParams
In init method, we should convert NamedList to SolrParams first, as SolrParams.get will search multiple paths including defaults settings.
NamedList args;
SolrParams params = SolrParams.toSolrParams(args);
Object obj = params.get(PARAM_MAX_THREAD);
Change SolrParams to NamedList
NamedList namedList = params.toNamedList();
Parse parameters in solrconfig or request
SolrParams params = SolrParams.toSolrParams(args);
List<String> fromFields = org.apache.solr.common.util.StrUtils.splitSmart(str, ",", true);
org.apache.solr.update.processor.SignatureUpdateProcessorFactory.inform(SolrCore)
final SchemaField field = core.getSchema().getFieldOrNull(getSignatureField());
if (null == field) {
  throw new SolrException
 (ErrorCode.SERVER_ERROR,
  "Can't use signatureField which does not exist in schema: "
  + getSignatureField());
}

Labels

adsense (5) Algorithm (69) Algorithm Series (35) Android (7) ANT (6) bat (8) Big Data (7) Blogger (14) Bugs (6) Cache (5) Chrome (19) Code Example (29) Code Quality (7) Coding Skills (5) Database (7) Debug (16) Design (5) Dev Tips (63) Eclipse (32) Git (5) Google (33) Guava (7) How to (9) Http Client (8) IDE (7) Interview (88) J2EE (13) J2SE (49) Java (186) JavaScript (27) JSON (7) Learning code (9) Lesson Learned (6) Linux (26) Lucene-Solr (112) Mac (10) Maven (8) Network (9) Nutch2 (18) Performance (9) PowerShell (11) Problem Solving (11) Programmer Skills (6) regex (5) Scala (6) Security (9) Soft Skills (38) Spring (22) System Design (11) Testing (7) Text Mining (14) Tips (17) Tools (24) Troubleshooting (29) UIMA (9) Web Development (19) Windows (21) xml (5)