# Getting started with PyLucene # Easy example, largely cribbed from http://www.inkdroid.org/talks/pylucene/ from PyLucene import Field, Document, StandardAnalyzer, FSDirectory, \ IndexWriter, Field, IndexSearcher, QueryParser store = FSDirectory.getDirectory( "pylucene-index", True ) writer = IndexWriter( store, StandardAnalyzer(), True ) d = Document() d.add ( Field.Text("body","""Some searchable text about me Comments on Christopher Schmidt: Web Development Services Copyright 2003-2005, Christopher Schmidt""")) writer.addDocument( d ) writer.close() string = "Christopher" directory = FSDirectory.getDirectory( 'pylucene-index', False ) searcher = IndexSearcher( directory ) query = QueryParser.parse( string, 'body', StandardAnalyzer() ) hits = searcher.search( query ) for i in range(0,hits.length()): doc = hits.doc(i) print "ID: %s" % doc.getField('body').stringValue()