Apache Lucen is a full text-search library for java which helps
you add search capability to your application/website.
Note that Lucene is specifically an API, not an application.
Apache Lucene is a power full search library on which the
widely used search engines like Apache Solr,ElasticSearch are based
You can add contents to Lucene from various sources,like a SQL/NoSQL database, a filesystem, or even from websites.
Some Terminologies
Index
Lucene uses index called an inverted index, because it inverts
a page-centric data structure (page->words) to a keyword-centric
data structure (word->pages).
Document
An index consists of one or more Documents.
Indexing involves adding Documents to an IndexWriter,
and searching involves retrieving Documents from an index via an IndexSearcher.
Fields
A Document consists of one or more Fields. A Field is simply a name-value pair.
Let's get started:
For quickly getting started I am going to create an In-Memory Index.
Step-1
Create an empty Maven project using the following console command:
$ mvn archetype:create -DgroupId=demo.lucene -DartifactId=lucene-demo
Step-2
Add Lucene dependencies to pom.xml
file as defined below
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>demo.lucene</groupId>
<artifactId>lucene-demo</artifactId>
<version>1.0</version>
<name>Lucene-HelloWorld</name>
<description>Hello World Lucene Search Example</description>
<dependencies>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>lucene</groupId>
<artifactId>lucene</artifactId>
<version>1.4.3</version>
</dependency>
</dependencies>
</project>
Step-3
Create a Java file HelloWorldLucene.java
class
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.StringField;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopScoreDocCollector;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.Version;
import java.io.IOException;
public class HelloLucene {
public static void main(String[] args) throws IOException, ParseException {
// Specify the analyzer for tokenizing text.
// The same analyzer should be used for indexing and searching
StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_40);
// Create the index
Directory index = new RAMDirectory();
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_40, analyzer);
IndexWriter w = new IndexWriter(index, config);
addDoc(w, "Lucene in Action", "193398817");
addDoc(w, "Lucene for Dummies", "55320055Z");
addDoc(w, "Managing Gigabytes", "55063554A");
addDoc(w, "The Art of Computer Science", "9900333X");
w.close();
//Query
String querystr = args.length > 0 ? args[0] : "lucene";
// the "title" arg specifies the default field to use
// when no field is explicitly specified in the query.
Query q = new QueryParser(Version.LUCENE_40, "title", analyzer).parse(querystr);
// Search
int hitsPerPage = 10;
IndexReader reader = DirectoryReader.open(index);
IndexSearcher searcher = new IndexSearcher(reader);
TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage, true);
searcher.search(q, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
// Display results
System.out.println("Found " + hits.length + " hits.");
for(int i=0;i<hits.length;++i) {
int docId = hits[i].doc;
Document d = searcher.doc(docId);
System.out.println((i + 1) + ". " + d.get("isbn") + "\t" + d.get("title"));
}
// reader can only be closed when there
// is no need to access the documents any more.
reader.close();
}
private static void addDoc(IndexWriter w, String title, String isbn) throws IOException {
Document doc = new Document();
doc.add(new TextField("title", title, Field.Store.YES));
// Use a string field for isbn because we don't want it tokenized
doc.add(new StringField("isbn", isbn, Field.Store.YES));
w.addDocument(doc);
}
}
Step-4
Compile project
$ mvn clean package
Step-5
Run Project
$ java -jar <jar_name> <Main-Class_name> <query_string>
In our case run command:
$ java -jar lucene-demo-1.0.jar HelloWorldLucen "lucene"
18 comments
Eskişehir
Adana
Sivas
Kayseri
Samsun
S622Y
yozgat
tunceli
hakkari
zonguldak
adıyaman
NV3Y5
sakarya
elazığ
sinop
siirt
van
K3YD
ankara
sakarya
tekirdağ
kastamonu
amasya
W5COS
ankara parça eşya taşıma
takipçi satın al
antalya rent a car
antalya rent a car
ankara parça eşya taşıma
R83ZZU
kayseri evden eve nakliyat
samsun evden eve nakliyat
muğla evden eve nakliyat
bursa evden eve nakliyat
bingöl evden eve nakliyat
XRO6B
bartın evden eve nakliyat
edirne evden eve nakliyat
mersin evden eve nakliyat
sinop evden eve nakliyat
siirt evden eve nakliyat
DCMBO
EE727
Tekirdağ Boya Ustası
Mardin Evden Eve Nakliyat
Osmaniye Evden Eve Nakliyat
Aydın Evden Eve Nakliyat
Maraş Evden Eve Nakliyat
B4C4B
Adana Parça Eşya Taşıma
Tekirdağ Şehirler Arası Nakliyat
Afyon Parça Eşya Taşıma
Karabük Şehir İçi Nakliyat
Kripto Para Borsaları
Siirt Parça Eşya Taşıma
AAX Güvenilir mi
Gölbaşı Parke Ustası
Siirt Lojistik
F1AE6
Ünye Oto Lastik
Adıyaman Şehir İçi Nakliyat
Poloniex Güvenilir mi
Ünye Çekici
Adıyaman Parça Eşya Taşıma
Uşak Parça Eşya Taşıma
Hakkari Lojistik
Ankara Parke Ustası
Trabzon Parça Eşya Taşıma
9CBB9
Karabük Parça Eşya Taşıma
Batman Lojistik
Keçiören Parke Ustası
Diyarbakır Parça Eşya Taşıma
Uşak Şehirler Arası Nakliyat
Probit Güvenilir mi
Edirne Lojistik
Çorum Şehir İçi Nakliyat
Diyarbakır Şehirler Arası Nakliyat
0DE89
binance
EEB17
binance %20
6CF9F
Coin Nedir
Telegram Abone Hilesi
Facebook Sayfa Beğeni Hilesi
Binance Neden Tercih Edilir
Soundcloud Dinlenme Hilesi
Bitcoin Nasıl Oynanır
Threads Takipçi Hilesi
Kripto Para Nasıl Oynanır
Twitter Beğeni Hilesi
FF0AE
Bonk Coin Hangi Borsada
Xcn Coin Hangi Borsada
Mexc Borsası Güvenilir mi
Binance Hesap Açma
Bee Coin Hangi Borsada
Kripto Para Kazanma Siteleri
Mexc Borsası Güvenilir mi
Dlive Takipçi Satın Al
Binance Referans Kodu
8BDEA
Mexc Borsası Güvenilir mi
Binance Madenciliği Nedir
Referans Kimliği Nedir
Alya Coin Hangi Borsada
Clysterum Coin Hangi Borsada
Okex Borsası Güvenilir mi
Bitcoin Nasıl Oynanır
Parasız Görüntülü Sohbet
Binance Para Kazanma
2DAB2
Youtube Abone Hilesi
Btcst Coin Hangi Borsada
Bitcoin Nedir
Btcturk Borsası Güvenilir mi
Bitcoin Nasıl Üretilir
Telcoin Coin Hangi Borsada
Parasız Görüntülü Sohbet
Osmo Coin Hangi Borsada
Tesla Coin Hangi Borsada
6DFC2C6524
görüntülü show
şov
cialis
www.ijuntaxmedikal.store
steroid satın al
steroid satın al