Stephan
Stephan

Reputation: 207

Hibernate Search query for class

I'm using hibernate search 4.4.0. And I met a problem recently.

E.g, I have 2 classes INDEXING and DATA_PROPERTY. There is no association between 2 of them. And I can't change them or creat a new class to associate 2 of them.

Part of Lucene indexing:

mapping.entity(DatatypeProperty.class).indexed().providedId()
       .property("rdfResource",ElementType.FIELD).field().analyze(Analyze.NO).store(Store.YES)
       .property("partitionValue", ElementType.FIELD).field().analyze(Analyze.NO)

mapping.entity(Indexing.class).indexed().providedId()
       .property("rdfResource",ElementType.FIELD).field().analyze(Analyze.NO).store(Store.YES)

Now in the SQL, I use

SELECT IND.RDF_RESOURCE 
FROM INDEXING IND, DATA_PROPERTY DP
WHERE IND.RDF_RESOURCE = DP.RDF_RESOURCE
AND IND.OBJECT_TYPE_ID_INDEXED IN (........)
AND DP.PARTITION_VALUE IN (......)
AND .......

How can I translate IND.RDF_RESOURCE = DP.RDF_RESOURCE in Hibernate Search???

I thought maybe I can use the query to find all the RDF_RESOURCE of class DatatypeProperty and matching all of them in the query for class Indexing. But it seems very inefficiency.

Does anyone has a better way for this?

Upvotes: 1

Views: 141

Answers (1)

Hardy
Hardy

Reputation: 19129

I have 2 classes INDEXING and DATA_PROPERTY. There is no association between 2 of them. And I can't change them or create a new class to associate 2 of them.

In this case you are between a rock and a hard place. You will need to associate the records somehow and the most obvious choice is via an association. Also, you cannot compare a SQL join with a free text based index provided by Lucene.

One potential solution could be to write a custom bridge which at indexing time executes the join and indexes the relevant data, so that you can target it directly via your query. Whether this works for you will depend on your use case. In your example setup, I don't see any field which would benefit from free text search. I can only assume that you are only showing parts of your code. If not, why don't you just stick with SQL?

Upvotes: 1

Related Questions