Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lucene : Text Search IG5 – TILE Esther Pacitti. Basic Architecture.

Similar presentations


Presentation on theme: "Lucene : Text Search IG5 – TILE Esther Pacitti. Basic Architecture."— Presentation transcript:

1 Lucene : Text Search IG5 – TILE Esther Pacitti

2 Basic Architecture

3 Indexing The documents are the textual objects you want to index. A Document is a set of fields Each field has a key and a value (e.g. Title = « Luncene… ») The IndexWriter is the java object that will process the documents to add them in the LuceneIndex

4 Indexing Document doc = new Document(); Field f = new Field("title","le titre du document"); doc.add(f); iwriter.addDocument(doc);

5 Indexing Indexing (full code) Directory directory = new RAMDirectory();//LuceneIndex : in memory; Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_43);//How to process string; IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_43, analyzer); IndexWriter iwriter = new IndexWriter(directory, config); Document doc = new Document(); Field f = new Field(“title”,”le titre du document”); doc.add(f); iwriter.addDocument(doc);

6 Searching Users can submit keyword queries The IndexSearcher will search the most relevant items noted hits with respect to the Query that are indexed in LuceneIndex Directory Each hit in Hits is associated to a score representing its relevance with respect to Query Hits are sorted in decreasing order of score

7 Searching Query q = parser.parse(“my query”); ScoreDoc[] hits = isearcher.search(q, null, 10).scoreDocs; //10 is maximum number of documents the system will return for (int i = 0; i < hits.length; i++) { Document hitDoc = isearcher.doc(hits[i].doc); System.out.println( hitDoc.get(“title") +” with a score of “+hits[i].score); }

8 Searching (full code) IndexSearcher isearcher = new IndexSearcher(DirectoryReader.open(directory)); QueryParser parser = new QueryParser(Version.LUCENE_43, "title", analyzer);//On indique sur quel(s) champ(s) des documents la recherche doit être faite Query q = parser.parse(“my query”); ScoreDoc[] hits = isearcher.search(q, null, 10).scoreDocs; for (int i = 0; i < hits.length; i++) { Document hitDoc = isearcher.doc(hits[i].doc); System.out.println( hitDoc.get(“title") +” with a score of “+hits[i].score); }


Download ppt "Lucene : Text Search IG5 – TILE Esther Pacitti. Basic Architecture."

Similar presentations


Ads by Google