public void givenSortFieldWhenSortedThenCorrect() {
InMemoryLuceneIndex inMemoryLuceneIndex
= new InMemoryLuceneIndex(new RAMDirectory(), new StandardAnalyzer()); inMemoryLuceneIndex.indexDocument("Ganges", "River in India"); inMemoryLuceneIndex.indexDocument("Mekong", "This river flows in south Asia"); inMemoryLuceneIndex.indexDocument("Amazon", "Rain forest river"); inMemoryLuceneIndex.indexDocument("Rhine", "Belongs to Europe"); inMemoryLuceneIndex.indexDocument("Nile", "Longest River");
Term term = new Term("body", "river");
Query query = new WildcardQuery(term);
SortField sortField
= new SortField("title", SortField.Type.STRING_VAL, false);
Sort sortByTitle = new Sort(sortField);
List documents
= inMemoryLuceneIndex.searchIndex(query, sortByTitle);
assertEquals(4, documents.size());
assertEquals("Amazon", documents.get(0).getField("title").stringValue());
}
Biz olingan hujjatlarni daryolarning nomlari bo'lgan sarlavha maydonlari bo'yicha saralashga harakat qildik. SortField konstruktoriga mantiqiy argument tartiblash tartibini teskari o'zgartirish uchundir.
8. Indeksdan hujjatlarni olib tashlang Keling, ma'lum bir muddatga asoslanib, ba'zi hujjatlarni indeksdan olib tashlashga harakat qilaylik:
// ...
IndexWriterConfig indexWriterConfig = new IndexWriterConfig(analyzer); IndexWriter writer = new IndexWriter(memoryIndex, indexWriterConfig); writer.deleteDocuments(term);
// ...
Biz buni sinab ko'ramiz:
@Test
public void whenDocumentDeletedThenCorrect() {
InMemoryLuceneIndex inMemoryLuceneIndex
= new InMemoryLuceneIndex(new RAMDirectory(), new StandardAnalyzer()); inMemoryLuceneIndex.indexDocument("Ganges", "River in India"); inMemoryLuceneIndex.indexDocument("Mekong", "This river flows in south Asia");
Term term = new Term("title", "ganges"); inMemoryLuceneIndex.deleteDocument(term);
Query query = new TermQuery(term);
List documents = inMemoryLuceneIndex.searchIndex(query); assertEquals(0, documents.size());
}
Ushbu maqola Apache Lucene bilan ishlashni boshlash uchun tezkor kirish edi. Shuningdek, biz turli so'rovlarni bajardik va olingan hujjatlarni saraladik.
Har doimgidek misollar uchun kodni Github-da topish mumkin.
Xulosa.
Men bu mustaqil ishni bajarish davomida Lucene haqida ma’lumotlarga ega bo’ldim. Uni qanday manoga egaligi. Qanday ishlashini , qanday xususiyatlarga ega ekanligi haqida ma’lumotga ega bo’ldim. Biznes jarayoni har qanday tashkiliy tuzilmani tushunish uchun asosiy tushunchadir. Lucene kabi texnologiya murakkab biznes jarayonlarini samarali boshqarishga yordam beradi. Lucene - bu Apache jamg'armasining bepul yuqori samarali to'liq matnli qidiruv kutubxonasi bo'lib, 2010-yillarning o'rtalarida Elasticsearch va Solr uchun eng mashhur replikatsiyalangan qidiruv tizimlari uchun asos bo'lib xizmat qiladi. Java tilida yozilgan.
Ish jarayoni biznes mantig'ining ko'rinishini va moslashuvchanligini sezilarli darajada yaxshilaydi.
Foydalanilgan adabiyotlar
Google.com
baeldung.com
WaveAcces
Do'stlaringiz bilan baham: |