I want to use hibernate search,through netbeans for search by keyword on my database.Using Lucene I am able to search through 1 table but as I have multiple tables,I need to search on them also.Kindly Help me..as I am new to Lucene I am not able to manipulate the indexes or its search techniques.
Here is the sample of code: package beans.search; import java.io.IOException; import java.io.StringReader; import org.apache.lucene.document.Field; import org.apache.lucene.document.Document;
import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.index.IndexWriter; //import org.apache.lucene.index.MultiSearcher; import beans.business.Jobdetails; import java.util.List; import manager.JobManager;
//import org.apache.lucene.util.Version; //import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.analysis.Analyzer; /** * */ public class Indexer { /** Creates a new instance of Indexer */ public Indexer() { System.out.println("I am in indexer()"); } //StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_40); private IndexWriter indexWriter = null; //IndexWriterConfig indexWriterConfig = new IndexWriterConfig(Version.LUCENE_40); //IndexWriterConfig indexWriterConfig = new IndexWriterConfig(Version.LUCENE_40); public IndexWriter getIndexWriter(boolean create) throws IOException { //System.out.println("I am in getWriter()"); if (indexWriter == null) { indexWriter = new IndexWriter("index-directory",new StandardAnalyzer(),create); System.out.println("index-directory created"); } return indexWriter; } public void closeIndexWriter() throws IOException { System.out.println("I am in closeIndexWriter()"); if (indexWriter != null) { indexWriter.close(); } } public void indexHotel(Jobdetails jobdetails) throws IOException { //System.out.println("I am in indexHotel()");
//System.out.println("Indexing hotel: " + jobdetails); IndexWriter writer = getIndexWriter(false); Document doc = new Document(); // doc.add(new Field("id", hotel.getId(), Field.Store.YES, Field.Index.NO)); //doc.add(new Field("jobcode", jobdetails.getJobcode(), Field.Store.YES, Field.Index.TOKENIZED)); doc.add(new Field("jobtitle", jobdetails.getJobtitle(), Field.Store.YES, Field.Index.UN_TOKENIZED)); doc.add(new Field("jobtype", jobdetails.getJobtype(), Field.Store.YES, Field.Index.TOKENIZED)); String fullSearchableText = jobdetails.getJobcode() + " " + jobdetails.getJobtitle() + " " +jobdetails.getJobtype() ; doc.add(new Field("content", fullSearchableText, Field.Store.NO, Field.Index.TOKENIZED)); writer.addDocument(doc); } public void rebuildIndexes() throws IOException { // // Erase existing index // //System.out.println("I am in rebuildIndexes()"); getIndexWriter(true); // // Index all Accommodation entries // //indexHotel(hotel); List<Jobdetails> allJobs = new JobManager().getAllJobs(); for (int i=0;i<allJobs.size();i++) { Jobdetails jobdetails = allJobs.get(i); indexHotel(jobdetails); } // // Don't forget to close the index writer when done // closeIndexWriter(); } } For tracing the compiler I have Used statements like I am in closewriter()..etc
Thanks in advance.
|