lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aleksei Valikov <vali...@gmx.net>
Subject SQL-Like Join in Lucene
Date Thu, 10 Aug 2006 16:18:20 GMT
Hi.

I'm investigating a possibility to make a "join" in Lucene/Compass.

Here's the thread:
http://forums.opensymphony.com/thread.jspa?threadID=39685&tstart=0

I have records m:m entities. Entities hold indexed information. Records consist 
of entities. One entity may belong to many records.
I would like to search for records having certain entity information.

Entity documents contain indexable entity fields plus entity id.
Record documents contain indexable record fielfs, record id and entity ids.

I'd like to "search for records having entity ids in (search for entity ids 
where entity fields satisfy condition)".

Currently I am using self-written InSetFilter to accomplish the task.
1. Search among entities by the given condition.
2. Put ids of the found entities into a set.
3. Create filter with this set.
4. Search for records with filter.

The join is basically implemented by a filter:

	public BitSet bits(IndexReader reader) throws IOException {

		BitSet bits = new BitSet(reader.maxDoc());

		int[] docs = new int[1];
		int[] freqs = new int[1];
		for (Iterator iterator = set.iterator(); iterator.hasNext();) {
			final String id = (String) iterator.next();
			final TermDocs termDocs = reader.termDocs(new Term(fieldName, id));
			final int count = termDocs.read(docs, freqs);
			if (count == 1) {
				bits.set(docs[0]);
			}
		}
		return bits;
	}

Is this approach ok or I missed something and there's an easier way to join?

Thank you for you time.

Bye.
/lexi

---------------------------------------------------------------------
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