General steps for creating an index in solrj:
1) create a solrserver object, which is used to manage indexes.
2) create a solrinputdocument object, that is, a document object, and add fields to the Document Object.
3) use the Add method of the solrserver object to add the solrinputdocument object and create an index.
4) Call The COMMIT () method of the solrserver object to submit the index.
For example:
Httpsolrserver HSS = new httpsolrserver ("http: // localhost: 8080/SOLR ");
Solrinputdocument = new solrinputdocument ();
Solrinputdocument. addfield ("ID", 1 );
Solrinputdocument. addfield ("uname", "zhangsan ");
Solrinputdocument. addfield ("sex", sex. Male. tostring ());
Solrinputdocument. addfield ("Age", 1 );
Solrinputdocument. addfield ("holobby", "basketball ");
HSS. Add (solrinputdocument );
HSS. Commit ();
General Search Steps:
1) create a solrserver object
2) create a query statement solrquery object
3) create a solrrequest object
4) generate a solrresponse object through the solrrequest process (solrserver) Method
5) Call the getresults () method of the solrresponse object to obtain the result set.
Here we can also directly create a solrresponse object through solrserver's query (solrquery.
For example:
1. httpsolrserver HSS = new httpsolrserver ("http: // localhost: 8080/SOLR ");
Solrquery sq = new solrquery ("ID: 1 ");
Queryrequest QR = new queryrequest (SQ );
Queryresponse q = QR. Process (HSS );
Solrdocumentlist list = Q. getresults ();
Solrdocument SD = list. Get (0 );
System. Out. println (SD. Get ("uname "));
2. httpsolrserver HSS = new httpsolrserver ("http: // localhost: 8080/SOLR ");
Solrquery sq = new solrquery ("*:*");
Queryresponse QR = HSS. Query (SQ );
Solrdocumentlist list = QR. getresults ();
For (solrdocument SD: List)
{
Iterator iter = SD. keyset (). iterator ();
For (; ITER. hasnext ();)
{
String key = (string) ITER. Next ();
Object value = SD. Get (key );
System. Out. println (Key + "---->" + value );
}
System. Out. println ("----------------------------");
}
SOLR Note 4-General steps to create an index and search for solrj