lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From TechRay <>
Subject How to Phrase Search Query with wild card
Date Wed, 07 Aug 2013 13:50:51 GMT
(Please note that I am very new to lucene/hibernate and any sort of database
usage that isn't straightforward SQL queries)

I am using hibernate with Lucene and I am trying to do a search query that
when "Foo B" is searched it would display records with say a 'title' of "Foo
Bar", a 'description' of "Foo Bear", and a 'name' of "Foo Berry", but would
*NOT* return a result set of records with say a 'title' of "Foo" and a
'name' of "Bar", or even a title of "Foo Aplha" and a 'name' of "Bar Stool",
so basically searching for the phrase as one entity and not really breaking
it up.

Now I have found a lot of things online, but most say something like 'just
use complexphrasequery/multiphrasequery' and I am very unclear on actually
how to go about using those as any example I see usually has vague instances
of objects that doesn't show its initialization of what it actually is, or
it is outdated and those methods don't really exist anymore. The following
is something I've been trying to play around with to get to work, but it's
just a mess 

		Session hibernateSession = this.getSession();
		List<T> results;
		FullTextSession fullTextSession = Search

		Term firstTerm = new Term("jobTitle", "entry");
		Term secondTerm = new Term("jobTitle", "art*");

		MultiPhraseQuery multiPhrasequery = new MultiPhraseQuery();

		try {
			File index = new File("/var/lucene/indexes");
			Directory indexDirectory =;
			PrefixTermEnum reader = new
PrefixTermEnum(, secondTerm);
			TermEnum te = reader;
			List<Term> termList = new LinkedList<Term>();
			while ( {
				Term t = te.term();
				if (!t.field().equals("field") ||
!t.text().startsWith(secondTerm.text())) {
			Term[] terms = termList.toArray(new Term[0]);


			org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(
					multiPhrasequery, this.type);
			results = hibQuery.list();

Any help would be appreciated, any code examples would be greatly

View this message in context:
Sent from the Lucene - Java Users mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message