-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: without using maven how to use hibernate search in netbeans
PostPosted: Sun Nov 18, 2012 6:59 pm 
Newbie

Joined: Sun Nov 18, 2012 6:42 pm
Posts: 1
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.


Top
 Profile  
 
 Post subject: Re: without using maven how to use hibernate search in netbeans
PostPosted: Fri Nov 23, 2012 6:40 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
What is your actual problem and question? If you are new to Hibernate Search why do you not start with the "Getting started" section of the documentation - http://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#getting-started?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.