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
120
Spring Framework 5.2 - Core Container Revisited
ejug
0
140
Andreas Caternberg on Jenkins Pipelines
ejug
0
670
Martin Ahrer on Continuous Delivery Infrastructure With Docker
ejug
0
140
Dirk Mahler on Software Analyse mit jQAssistant & Neo4j
ejug
1
270
Christoph Strobl on Spring Data & Hypermedia
ejug
0
100
Stefan Armbruster on Graph Modelling Antipatterns
ejug
1
110
Stefan Armbruster on Introduction into Neo4J
ejug
1
81
Michael Nitschinger on Building a reactive Couchbase driver for the JVM
ejug
0
120
Other Decks in Technology
See All in Technology
Introduction to Sansan for Engineers / エンジニア向け会社紹介
sansan33
PRO
5
43k
研究開発部メンバーの働き⽅ / Sansan R&D Profile
sansan33
PRO
3
20k
Biz職でもDifyでできる! 「触らないAIワークフロー」を実現する方法
igarashikana
3
1.3k
Kubernetes self-healing of your workload
hwchiu
0
320
ソフトウェアエンジニアの生成AI活用と、これから
lycorptech_jp
PRO
0
780
Copilot Studio ハンズオン - 生成オーケストレーションモード
tomoyasasakimskk
0
190
webpack依存からの脱却!快適フロントエンド開発をViteで実現する #vuefes
bengo4com
0
1.1k
混合雲環境整合異質工作流程工具運行關鍵業務 Job 的經驗分享
yaosiang
0
140
Building a cloud native business on open source
lizrice
0
140
映像エッジAIにおけるNode-RED活用事例
emirmatsui
0
120
Contract One Engineering Unit 紹介資料
sansan33
PRO
0
8.9k
速習AGENTS.md:5分で精度を上げる "3ブロック" テンプレ
ismk
6
1.9k
Featured
See All Featured
Reflections from 52 weeks, 52 projects
jeffersonlam
353
21k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.5k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
253
22k
Being A Developer After 40
akosma
91
590k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
Balancing Empowerment & Direction
lara
5
700
The Cost Of JavaScript in 2023
addyosmani
55
9.1k
RailsConf 2023
tenderlove
30
1.3k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.7k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Mobile First: as difficult as doing things right
swwweet
225
10k
Building an army of robots
kneath
306
46k
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!