Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Christoph Strobl on spring-data-solr
Search
Enterprise Java User Group Austria
September 25, 2013
Technology
0
200
Christoph Strobl on spring-data-solr
Enterprise Java User Group Austria
September 25, 2013
Tweet
Share
More Decks by Enterprise Java User Group Austria
See All by Enterprise Java User Group Austria
Gerrit Grunwald on What the CRaC... SUPERFAST JVM STARTUP
ejug
2
95
Spring Framework 5.2 - Core Container Revisited
ejug
0
120
Andreas Caternberg on Jenkins Pipelines
ejug
0
540
Martin Ahrer on Continuous Delivery Infrastructure With Docker
ejug
0
120
Dirk Mahler on Software Analyse mit jQAssistant & Neo4j
ejug
1
220
Christoph Strobl on Spring Data & Hypermedia
ejug
0
81
Stefan Armbruster on Graph Modelling Antipatterns
ejug
1
90
Stefan Armbruster on Introduction into Neo4J
ejug
1
76
Michael Nitschinger on Building a reactive Couchbase driver for the JVM
ejug
0
100
Other Decks in Technology
See All in Technology
NFV基盤のOpenStack更新 ~9世代バージョンアップへの挑戦~
vtj
0
330
株式会社EventHub・エンジニア採用資料
eventhub
0
4.3k
Perlの生きのこり - エンジニアがこの先生きのこるためのカンファレンス2025
kfly8
1
240
ウォンテッドリーのデータパイプラインを支える ETL のための analytics, rds-exporter / analytics, rds-exporter for ETL to support Wantedly's data pipeline
unblee
0
110
【詳説】コンテンツ配信 システムの複数機能 基盤への拡張
hatena
0
190
MIMEと文字コードの闇
hirachan
2
1.4k
プロダクトエンジニア 360°フィードバックを実施した話
hacomono
PRO
0
130
Snowflakeの開発・運用コストをApache Icebergで効率化しよう!~機能と活用例のご紹介~
sagara
1
310
ビジネスモデリング道場 目的と背景
masuda220
PRO
9
690
エンジニアが加速させるプロダクトディスカバリー 〜最速で価値ある機能を見つける方法〜 / product discovery accelerated by engineers
rince
4
530
ESXi で仮想化した ARM 環境で LLM を動作させてみるぞ
unnowataru
0
150
コンピュータビジョンの社会実装について考えていたらゲームを作っていた話
takmin
1
570
Featured
See All Featured
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
100
18k
The Cost Of JavaScript in 2023
addyosmani
47
7.3k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
4
430
Designing for Performance
lara
604
68k
Code Reviewing Like a Champion
maltzj
521
39k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.2k
GitHub's CSS Performance
jonrohan
1030
460k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Building an army of robots
kneath
303
45k
Git: the NoSQL Database
bkeepers
PRO
427
65k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
10
500
Transcript
Spring Data Solr I n t r o d u
c t i o n t o 2013-09-25, Christoph Strobl @eJUG, 48.299707,14.286896
Christoph Strobl Software Engineer Project Lead Spring Data Solr
[email protected]
@stroblchristoph https:/ /github.com/christophstrobl
Apache Solr ...in a hurry...
Apache Solr Enterprise Search Server Built on top of Lucene
Open Interfaces Multiple Collections Clusterable ...
Infrastructure Setup Solr
ZK Infrastructure Setup S1L S1R S2L S2R
ZK Infrastructure Setup S1L S1R S2L S2R
Inside Solr Cores Schema
Solr Schema Types Analysers Fields <fieldType name="string" class="solr.StrField" sortMissingLast="true" />
<fieldType name="lowercase" class="solr.TextField"> <analyzer> <tokenizer class="solr.KeywordTokenizerFactory"/> <filter class="solr.LowerCaseFilterFactory" /> </analyzer> </fieldType> <field name="name_ci" type="lowercase" indexed="true" stored="false"/>
Schemaless since 4.4
Connection HTTP SolrJ q=name:(spring data) AND type:solr&start=0&rows=10 new SolrQuery("name:(spring data)
AND type:solr") .setStart(0).setRows(10);
Solr Query public List<Product> findByNameOrDescription(String name, String description) { String
queryString = "name:" + ClientUtils.escapeQueryChars(name) + " OR description:" + ClientUtils.escapeQueryChars(description); try { SolrQuery query = new SolrQuery(queryString); query.setStart(0).setRows(0); QueryResponse response = solrServer.query(query); long totalValues = response.getResults().getNumFound(); query.setRows(Long.valueOf(totalValues).intValue()); return solrServer.query(query).getBeans(Product.class); } catch (SolrServerException e) { throw ExceptionTranslator.translate(e); } return Collections.emptyList(); }
Spring-Data-Solr
Spring-Data-Solr Spring Data offers serveral APIs around a common SPI
Integration with Apache Solr Community Project with support from pivotal
Connection HTTP SolrJ Spring Data Solr new SimpleQuery(new Criteria("name") .is("spring",
"data").and("type").is("solr") ).setPageRequest(new PageRequest(0, 10)); q=name:(spring data) AND type:solr&start=0&rows=10 new SolrQuery("name:(spring data) AND type:solr") .setStart(0).setRows(10);
Solr Template
SolrTemplate Product product = new Product("foo"); solrTemplate.saveBean(prodcut); solrTemplate.commit(); //... Product
recalled = solrTemplate.queryForObject( new SimpleQuery(new Criteria("id").is("foo")), Product.class); Page<Product> page = solrTemplate.queryForPage( new SimpleQuery(new SimpleStringCriteria("*:*"), Product.class); //... solrTemplate.deleteById("foo"); solrTemplate.commit();
Repository
Repository interface ProductRepository extends SolrCrudRepository<Product, String> { } Product product
= new Product("foo"); repo.save(product) //... Product recalled = repo.findOne("foo"); Page<Product> page = repo.findAll(); //... repo.delete(product);
Derived Queries
Derived Queries interface ProductRepository extends SolrCrudRepository<Product, String> { Page<Product> findByNameStartingWith(String
name, Pageable page); List<Product> findByNameOrDescription(@Boost(2) String name, String description); } Page<Product> page = repo.findByNameStartingWith("fo", new PageRequest(0,10)); List<Product> list = repo.findByNameOrDescription("foo", "foo");
/*Named*/ Queries
/*Named*/ Queries interface ProductRepository extends SolrCrudRepository<Product, String> { @Query("name:?0*") Page<Product>
findByNameStartingWith(String name, Pageable page); @Query(name="findByNameOrDescriptionBoostNameBy2") List<Product> findByNameOrDescription(String name, String description); }
Demo
Custom Repository
Faceting
Highlighting
Custom Types
Questions?
Thank you!