3 * Copyright (C) 2012 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.api
.service
.search
;
12 import java
.io
.IOException
;
13 import java
.util
.ArrayList
;
14 import java
.util
.HashSet
;
15 import java
.util
.List
;
17 import java
.util
.UUID
;
19 import org
.apache
.lucene
.document
.Document
;
20 import org
.apache
.lucene
.index
.CorruptIndexException
;
21 import org
.apache
.lucene
.search
.ScoreDoc
;
22 import org
.apache
.lucene
.search
.TopDocs
;
23 import org
.hibernate
.criterion
.Criterion
;
24 import org
.springframework
.stereotype
.Component
;
26 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
27 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.ICdmEntityDao
;
28 import eu
.etaxonomy
.cdm
.search
.LuceneSearch
;
31 * @author Andreas Kohlbecker
36 public class SearchResultBuilder
implements ISearchResultBuilder
{
39 * @see eu.etaxonomy.cdm.api.service.search.ISearchResultBuilder#createResultSetFromIds(eu.etaxonomy.cdm.search.LuceneSearch, org.apache.lucene.search.TopDocs, eu.etaxonomy.cdm.persistence.dao.common.ICdmEntityDao, java.lang.String)
43 * @param topDocsResultSet
47 * @throws CorruptIndexException
50 public <T
extends CdmBase
> List
<SearchResult
<T
>> createResultSetFromIds(LuceneSearch luceneSearch
, TopDocs topDocsResultSet
,
51 ICdmEntityDao
<T
> dao
, String idField
, List
<String
> propertyPaths
) throws CorruptIndexException
, IOException
{
53 List
<SearchResult
<T
>> searchResults
= new ArrayList
<SearchResult
<T
>>();
55 for (ScoreDoc scoreDoc
: topDocsResultSet
.scoreDocs
) {
56 Document doc
= luceneSearch
.getSearcher().doc(scoreDoc
.doc
);
57 String
[] idStrings
= doc
.getValues(idField
);
58 SearchResult
<T
> searchResult
= new SearchResult
<T
>(doc
);
59 //TODO use findByUuid(List<UUID> uuids, List<Criterion> criteria, List<String> propertyPaths)
60 // instead or even better a similar findById(List<Integer> ids) however this is not yet implemented
61 if(idStrings
.length
> 0){
62 T entity
= dao
.load(Integer
.valueOf(idStrings
[0]), propertyPaths
);
63 searchResult
.setEntity(entity
);
65 searchResults
.add(searchResult
);