lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From TechRay <houck...@gmail.com>
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
				.getFullTextSession(hibernateSession);
		fullTextSession.beginTransaction();

		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 = FSDirectory.open(index);
			@SuppressWarnings("resource")
			PrefixTermEnum reader = new
PrefixTermEnum(IndexReader.open(indexDirectory), secondTerm);
			
			TermEnum te = reader;
			List<Term> termList = new LinkedList<Term>();
			while (te.next()) {
				Term t = te.term();
				if (!t.field().equals("field") ||
!t.text().startsWith(secondTerm.text())) {
					break;
				}
				termList.add(t);
			}
			
			Term[] terms = termList.toArray(new Term[0]);

			multiPhrasequery.add(firstTerm);
			multiPhrasequery.add(secondTerm);

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

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



--
View this message in context: http://lucene.472066.n3.nabble.com/How-to-Phrase-Search-Query-with-wild-card-tp4083015.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message