1. solr 시작
Windows: bin\solr start
Mac, Linux: bin/solr start
2. 브라우저 실행
http://localhost:8983/solr
3. Core Collection 생성
Windows: bin\solr create -c record -d ..\server\solr\configsets\basic_configs
Mac, Linux: bin/solr create -c record -d ../server/solr/configsets/basic_configs
* v7.7.2 변경
solr create -c record -d ..\server\solr\configsets\_default
4. 생성 콜렉션 확인
http://localhost:8983/solr
5. $SOLR_HOME\server\solr\board\conf > managed-schema 수정
<field name="title" type="text_general" indexed="true" stored="true" multivalued="false" />
<field name="writer" type="string" indexed="true" stored="true" multivalued="false" />
<field name="board" type="text_general" indexed="true" stored="true" multivalued="false" />
<field name="date" type="date" indexed="true" stored="true" multivalued="false" />
<field name="text" type="text_general" indexed="true" stored="true" multivalued="true" />
<copyfield source="title" dest="text" />
<copyfield source="writer" dest="text" />
<copyfield source="board" dest="text" />
6. solr restart
Windows: bin\solr restart -p 8983
Mac, Linux: bin/solr restart
7. pom.xml
https://mvnrepository.com/artifact/org.apache.solr/solr-solrj
8. SolrJDriver.class 생성
public class SolrJDriver {
public static String url = "https://localhost:8983/solr/record";
public static SolrClient solr = new HttpSolrClient(url);
}
9. solr에 document 추가/삭제/조회
* 추가
SolrInputDocument solrDoc = new SolrInputDocument();
solrDoc.addField("id", param.getBrdno());
solrDoc.addField("title", param.getBrdtitle());
solrDoc.addField("writer", param.getBrdwriter());
solrDoc.addField("board", param.getBrdmemo());
solrDoc.addField("date", param.getBrddate());
Collection solrDocs = new ArrayList();
solrDocs.add(solrDoc);
SolrJDriver.solr.add(solrDocs);
SolrJDriver.solr.commit();
* 삭제
SolrJDriver.solr.deleteById(param);
SolrJDriver.solr.commit()
* 전체삭제
deleteByQuery(QUERY_STATEMENT)
* 조회
if(!"".equals(q)) {
SolrQuery query = new SolrQuery();
query.setQuery("text:" + q );
QueryResponse responseSolr = SolrJDriver.solr.query(".", query);
SolrDocumentList results = responseSolr.getResults();
modelMap.addAttribute("q", q);
modelMap.addAttribute("listview", results.toArray());
}
'solr' 카테고리의 다른 글
arirang 분석기 (0) | 2019.10.04 |
---|