1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2013 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
package eu.etaxonomy.cdm.api.service.search;
|
11
|
|
12
|
import java.io.IOException;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
import org.apache.lucene.search.DocIdSet;
|
16
|
import org.apache.lucene.search.DocIdSetIterator;
|
17
|
|
18
|
/**
|
19
|
* Helper class, for printing out information on {@link DocIdSet}s
|
20
|
*
|
21
|
* @author a.kohlbecker
|
22
|
* @date Sep 24, 2013
|
23
|
*
|
24
|
*/
|
25
|
public class DocIdBitSetPrinter {
|
26
|
|
27
|
public static final Logger logger = Logger.getLogger(DocIdBitSetPrinter.class);
|
28
|
|
29
|
public static String docsAsString(DocIdSet docset, int maxdocs){
|
30
|
|
31
|
StringBuilder sb = new StringBuilder();
|
32
|
try {
|
33
|
DocIdSetIterator it = docset.iterator();
|
34
|
int i = 0;
|
35
|
while(i < maxdocs){
|
36
|
int docId = it.nextDoc();
|
37
|
if(docId == DocIdSetIterator.NO_MORE_DOCS){
|
38
|
break;
|
39
|
}
|
40
|
sb.append(docId).append(" ");
|
41
|
}
|
42
|
} catch (IOException e) {
|
43
|
logger.error("Error while reding doc ids from DocIdSet", e);
|
44
|
}
|
45
|
|
46
|
return sb.toString();
|
47
|
}
|
48
|
|
49
|
}
|