Hi,
I'm trying to search in an index which as ManyToMany relations stored inside the index. Now I'm trying to get the value of the field by setting a projection on the query but I always get NULL values for all the ManyToMany fields! I already looked in to the index by using Luke and everything is fine. Even Luke gets the data for the fields and shows them...
So more precise:
Hibernate version: 3.3.1.GA
Hibernate Search version: 3.1.0GA
Hibernate Annotations version: 3.4.0GA
Hibernate Entitymanager version: 3.4.0GA
all retrieved by maven.
Mapping documents:
Document.class
Code:
@Indexed(index = "documents")
@Entity
@Table(name = "Documents", catalog = "vifachemPortal")
@AnalyzerDef(name = "fulltextanalyzer",
tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
filters = {
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = StopFilterFactory.class, params = {
@Parameter(name="words", value= "de/l3s/vifachem/db/test/stoplist.txt" ),
@Parameter(name="ignoreCase", value="true") }),
@TokenFilterDef(factory = EnglishPorterFilterFactory.class) })
public class Documents implements java.io.Serializable {
...
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(name = "DocumentsToKeywords", catalog = "vifachemPortal", joinColumns = { @JoinColumn(name = "id_doc", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "id_key", nullable = false, updatable = false) })
@IndexedEmbedded
public Set<Keywords> getKeywordses() {
return this.keywordses;
}
...
}
Keywords.classCode:
@Entity
@Table(name = "Keywords", catalog = "vifachemPortal")
public class Keywords implements java.io.Serializable {
...
@Column(name = "keyword", nullable = false, length = 200)
@Field(index=Index.UN_TOKENIZED, store=Store.YES)
public String getKeyword() {
return this.keyword;
}
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(name = "DocumentsToKeywords", catalog = "vifachemPortal", joinColumns = { @JoinColumn(name = "id_key", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "id_doc", nullable = false, updatable = false) })
@ContainedIn
public Set<Documents> getDocumentses() {
return this.documentses;
}
...
}
Let's search:Code:
DAOFactory daoFactory = DAOFactory.instance(DAOFactory.HIBERNATE);
DocumentsDAO ddao = daoFactory.getDocumentsDAO();
EntityManager em = ddao.getEntityManager();
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);
String[] queryFields = new String[]{"title", "abstract"};
Analyzer analyzer = fullTextEntityManager.getSearchFactory().getAnalyzer(Documents.class);
MultiFieldQueryParser parser = new MultiFieldQueryParser(queryFields, analyzer);
org.apache.lucene.search.Query query = parser.parse( "synthesis" );
FullTextQuery hibQuery = fullTextEntityManager.createFullTextQuery(query, Documents.class);
hibQuery.setProjection( FullTextQuery.SCORE, "title", "keywordses.keyword", FullTextQuery.THIS);
List<Object[]> results = hibQuery.getResultList();
for(Object[] result : results) {
float score = (Float)result[0];
String title = (String) result[1];
String keywords = (String) result[2];
Documents doc = (Documents) result[3];
System.out.println(score + ": " + title + "\n" + keywords);
System.out.println("\n");
}
Name and version of the database you are using:
MySQL 5.0.45
Here keywords is alwys NULL! So if there are any suggestions, you are really welcome!!!!
-- Sushi