lucene-java-user mailing list archives

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

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

Here's the thread:

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);
			final TermDocs termDocs = reader.termDocs(new Term(fieldName, id));
			final int count =, freqs);
			if (count == 1) {
		return bits;

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

Thank you for you time.


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

View raw message