The document discusses building your own search engine using Solr. It provides an overview of Solr, explaining that it is based on Lucene and provides text analysis, scoring algorithms, and a web-based interface. It also covers installing and deploying Solr, configuring schemas and fields, indexing data, and performing basic searches and more advanced search types like dismax and more-like-this queries.
5. An introduction to Solr
• Lucene 기반
– 텍스트 검색 엔진 라이브러리
– 다양한 텍스트 분석기 제공
– scoring 알고리즘
– text highlighter
• Solr는 Lucene의 서버 버전
– 문서 색인 및 질의를 HTTP request로 처리
– 빠른 질의 성능을 위해 cache 사용
– 웹기반 운영툴 제공
– 스키마, 서버 설정 파일
– disjunction-max 질의
– more-like-this 플러그인
– 분산 서버
6. Install & Deploy
1. http://lucene.apache.org/solr/ 접속한다.
2. 최신버전 (solr-4.2.1.zip) 다운로드한다.
3. 압축을 푼다.
4. cd example
java –jar start.jar
5. http://localhost:8983/solr/admin 확인한다.
• Apache Tomcat 이용 시 dist/solr-4.x.x.war 를 Apache
Tomcat 의 webapps 에 복사한다.
7. Schema & configuration file
• schema.xml
– 검색하고자 하는 데이터의 구조
– 데이터 필드 타입(<types>), 데이터 필드(<fields>)
– unique identified, 기본 검색 필드, 기본 연산자(AND/OR)
– 필드 복사
• solrconfig.xml
– 색인, 질의를 위한 파라미터
– <requestHandler>
14. Text analysis
1. <tokenizer class="solr.WhitespaceTokenizerFactory"/>
2. <filter class="solr.SynonymFilterFactory" synonyms=“synonyms.txt“
ignoreCase="true" expand="false"/>
3. <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt"/>
4. <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1“
generateNumberParts="1" catenateWords="1" catenateNumbers="1"
catenateAll="0“ splitOnCaseChange="1"/>
5. <filter class="solr.LowerCaseFilterFactory"/>
6. <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
Input) I can fly with SolrSearch if you can.
1. I, can, fly, with, SolrSearch, if, you, can
2. I, can, run, with, SolrSearch, if, you, can (“fly=>run” in synonyms.txt)
3. I, can, run, SolrSearch, if, you, can (“with” in stopwords.txt)
4. I, can, run, Solr, Search, if, you, can
5. i, can, run, solr, search, if, you, can
6. i, can, run, solr, search, if, you
15.
16. Indexing data
• http://localhost:8983/solr/update
• Sending XML to Solr
<add>
<doc>
<field name="employeeId">05991</field>
<field name="office">Bridgewater</field>
<field name="skills">Perl</field>
<field name="skills">Java</field>
</doc>
[<doc> ... </doc>[<doc> ... </doc>]]
</add>
• Deleting documents by ID and by Query
<delete><id>05991</id></delete>
<delete><query>office:Bridgewater</query></delete>
17. DataImportHandler
• XML 또는 relational DB 에서 직접 Solr 로 data를
import
• solrconfig.xml
<requestHandler name="/dataimport"
class="org.apache.solr.handler.dataimport.DataImportHandler"
>
<lst name="defaults">
<str name="config“>data-config.xml</str>
</lst>
</requestHandler>
• http://localhost:8983/solr/dataimport
19. Delta-import command
• 마지막 import 이후에 생성된 데이터만 import
• conf/dataimport.properties 에 마지막 import 시간
• http://localhost:8983/solr/dataimport?command=delta-
import
20. • data-config.xml
<dataConfig>
<dataSource driver="org.hsqldb.jdbcDriver"
url="jdbc:hsqldb:/temp/example/ex" user="sa" />
<document name="products">
<entity name="item" pk="ID"
query="select * from item"
deltaImportQuery="select * from item where
ID='${dih.delta.id}'"
deltaQuery="select id from item where
last_modified > '${dih.last_index_time}'">
</entity>
</document>
</dataConfig>
23. Dismax query
• Disjunction Max query
– Disjunction: 질의가 여러 필드를 대상으로 수행
– Max: 검색 대상 필드들의 가중치에 따라 score결정
• Query parameters
– qf: 필드 목록 및 가중치(예, subject^2.3 content tag^1.2)
– mm, pf, ps, tie, bq 등
37. 복합명사 분해
• 복합명사 검색
– “만성간염”이 “만성”, “간염”으로 분해
– 검색결과: “B형간염”, “A형간염”, “간염”, “만성간염”
• AND 검색을 위해 Korlucene 수정
– 수정 전
– 수정 후
– 참고) http://cafe.naver.com/korlucene/116
39. KoreanJasoFilter.java
int a, b, c; // 자소 버퍼: 초성/중성/종성 순
for (int i = 0; i < termLength; i++) {
char ch = termBuffer[i];
if (ch >= 0xAC00 && ch <= 0xD7A3) {
// "AC00:가" ~ "D7A3:힣" 에 속한 글자면 분해
c = ch - 0xAC00;
a = c / (21 * 28);
c = c % (21 * 28);
b = c / 28;
c = c % 28;
buffer.append(ChoSung[a]).append(JwungSung[b]);
if (c != 0) // c가 0이 아니면, 즉 받침이 있으면
buffer.append(JongSung[c]);
}
}
46. • 카테고리 분류 흐름도
Start
Fetch deal data
category
검색
category 예
존재
아니오
catedeal
검색
Grouping by
categoryid & score 가장 높은
catedeal 저장
summing category 선택
score
End
47. 위치 검색
• Solr spatial search 이용
• Schema configuration
<fieldType name=“latlon" class="solr.LatLonType“
subFieldSuffix="_coordinate"/>
<field name="location" type="latlon"
indexed="true" stored="true"/>
• Data
<field name=“location">37.775,-122.4232</field>
<field name=“location">40.7143,-74.006</field>
48. • geofilt – The distance filter
– pt: 위도, 경도 좌표
– sfield: 위치 검색 필드
– d: 거리(km)
http://localhost:8983/solr/select?wt=json&...&q=*:*
&fq={!geofilt pt=45.15,-93.85 sfield=location d=5}
• Search result
"response":{"numFound":8,"start":0,"docs":[
{ "name":"Samsung SpinPoint P120 SP2514N - hard drive - 250
GB - ATA-133",
“location":"45.17614,-93.87341"},
{ "name":"Maxtor DiamondMax 11 - hard drive - 500 GB -
SATA-300",
“location":"45.17614,-93.87341"}, …
• Java
SolrQuery query = new SolrQuery().
setFilterQueries("{!geofilt pt="+spatial.getLocation()+
" sfield=location d="+spatial.getDistance()+"}“);