本文整理汇总了Java中org.apache.lucene.search.Searcher.doc方法的典型用法代码示例。如果您正苦于以下问题:Java Searcher.doc方法的具体用法?Java Searcher.doc怎么用?Java Searcher.doc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.search.Searcher
的用法示例。
在下文中一共展示了Searcher.doc方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResultList
import org.apache.lucene.search.Searcher; //导入方法依赖的package包/类
public static List<Integer> getResultList(Searcher searcher, TopDocs docs,
int first, int max) throws CorruptIndexException, IOException {
List<Integer> list = new ArrayList<Integer>(max);
ScoreDoc[] hits = docs.scoreDocs;
if (first < 0) {
first = 0;
}
if (max < 0) {
max = 0;
}
int last = first + max;
int len = hits.length;
if (last > len) {
last = len;
}
for (int i = first; i < last; i++) {
Document d = searcher.doc(hits[i].doc);
list.add(Integer.valueOf(d.getField(ID).stringValue()));
}
return list;
}
示例2: generateConfidence
import org.apache.lucene.search.Searcher; //导入方法依赖的package包/类
public static Map<String, Float> generateConfidence(String indexFolder, String query, String field, int noOfPages, int maxValue)
throws Exception {
CustomValueSortedMap docNameScore = new CustomValueSortedMap(maxValue);
IndexReader reader = IndexReader.open(FSDirectory.open(new File(indexFolder)), true); // only searching, so read-only=true
Searcher searcher = new IndexSearcher(reader);
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
// Analyzer analyzer = new WhitespaceAnalyzer();
QueryParser parser = new QueryParser(Version.LUCENE_CURRENT, field, analyzer);
if (query != null) {
query = query.trim();
} else {
System.out.println("Wrong Query");
return null;
}
Query searchQuery = parser.parse(query);
ScoreDoc[] scoreDocs = doPagingSearch(searcher, searchQuery, noOfPages);
if (scoreDocs != null && scoreDocs.length > 0) {
for (int i = 0; i < scoreDocs.length; i++) {
Document document = searcher.doc(scoreDocs[i].doc);
/* Explanation exp = */searcher.explain(searchQuery, scoreDocs[i].doc);
String docPageType = fetchDocPageType(document.get("path"));
docNameScore.add(docPageType, Double.valueOf(scoreDocs[i].score));
}
}
reader.close();
return docNameScore.getReverseSortedMapValueInFloat();
}
示例3: getResultPage
import org.apache.lucene.search.Searcher; //导入方法依赖的package包/类
public static Pagination getResultPage(Searcher searcher, TopDocs docs,
int pageNo, int pageSize) throws CorruptIndexException, IOException {
List<Integer> list = new ArrayList<Integer>(pageSize);
ScoreDoc[] hits = docs.scoreDocs;
int endIndex = pageNo * pageSize;
int len = hits.length;
if (endIndex > len) {
endIndex = len;
}
for (int i = (pageNo - 1) * pageSize; i < endIndex; i++) {
Document d = searcher.doc(hits[i].doc);
list.add(Integer.valueOf(d.getField(ID).stringValue()));
}
return new Pagination(pageNo, pageSize, docs.totalHits, list);
}
示例4: initResultList
import org.apache.lucene.search.Searcher; //导入方法依赖的package包/类
private List<ResultDocument> initResultList(final Identity identity, final Roles roles, final Query query, final Analyzer analyzer, final Searcher searcher,
final TopDocs docs, final int firstResult, final int maxReturns, final boolean doHighlight) throws IOException {
final FieldSelector selector = new FieldSelector() {
@Override
public FieldSelectorResult accept(final String fieldName) {
return (doHighlight || !AbstractOlatDocument.CONTENT_FIELD_NAME.equals(fieldName)) ? FieldSelectorResult.LOAD : FieldSelectorResult.NO_LOAD;
}
};
maxHits = SearchServiceFactory.getService().getSearchModuleConfig().getMaxHits();
totalHits = docs.totalHits;
totalDocs = (docs.scoreDocs == null ? 0 : docs.scoreDocs.length);
final int numOfDocs = Math.min(maxHits, docs.totalHits);
final List<ResultDocument> res = new ArrayList<ResultDocument>(maxReturns + 1);
for (int i = firstResult; i < numOfDocs && res.size() < maxReturns; i++) {
final Document doc = searcher.doc(docs.scoreDocs[i].doc, selector);
final String reservedTo = doc.get(AbstractOlatDocument.RESERVED_TO);
if (StringHelper.containsNonWhitespace(reservedTo) && !"public".equals(reservedTo) && !reservedTo.contains(identity.getKey().toString())) {
continue;// admin cannot see private documents
}
final ResultDocument rDoc = createResultDocument(doc, i, query, analyzer, doHighlight, identity, roles);
if (rDoc != null) {
res.add(rDoc);
}
if (!roles.isOLATAdmin() && i % 10 == 0) {
// Do commit after certain number of documents because the transaction should not be too big
DBFactory.getInstance().intermediateCommit();
}
}
return res;
}
示例5: search
import org.apache.lucene.search.Searcher; //导入方法依赖的package包/类
/**
* Do the search.
*
* @param conn the database connection
* @param text the query
* @param limit the limit
* @param offset the offset
* @param data whether the raw data should be returned
* @return the result set
*/
protected static ResultSet search(Connection conn, String text,
int limit, int offset, boolean data) throws SQLException {
SimpleResultSet result = createResultSet(data);
if (conn.getMetaData().getURL().startsWith("jdbc:columnlist:")) {
// this is just to query the result set columns
return result;
}
if (text == null || text.trim().length() == 0) {
return result;
}
try {
IndexAccess access = getIndexAccess(conn);
// take a reference as the searcher may change
Searcher searcher = access.searcher;
// reuse the same analyzer; it's thread-safe;
// also allows subclasses to control the analyzer used.
Analyzer analyzer = access.writer.getAnalyzer();
QueryParser parser = new QueryParser(Version.LUCENE_30,
LUCENE_FIELD_DATA, analyzer);
Query query = parser.parse(text);
// Lucene 3 insists on a hard limit and will not provide
// a total hits value. Take at least 100 which is
// an optimal limit for Lucene as any more
// will trigger writing results to disk.
int maxResults = (limit == 0 ? 100 : limit) + offset;
TopDocs docs = searcher.search(query, maxResults);
if (limit == 0) {
limit = docs.totalHits;
}
for (int i = 0, len = docs.scoreDocs.length;
i < limit && i + offset < docs.totalHits
&& i + offset < len; i++) {
ScoreDoc sd = docs.scoreDocs[i + offset];
Document doc = searcher.doc(sd.doc);
float score = sd.score;
String q = doc.get(LUCENE_FIELD_QUERY);
if (data) {
int idx = q.indexOf(" WHERE ");
JdbcConnection c = (JdbcConnection) conn;
Session session = (Session) c.getSession();
Parser p = new Parser(session);
String tab = q.substring(0, idx);
ExpressionColumn expr = (ExpressionColumn) p.parseExpression(tab);
String schemaName = expr.getOriginalTableAliasName();
String tableName = expr.getColumnName();
q = q.substring(idx + " WHERE ".length());
Object[][] columnData = parseKey(conn, q);
result.addRow(
schemaName,
tableName,
columnData[0],
columnData[1],
score);
} else {
result.addRow(q, score);
}
}
} catch (Exception e) {
throw convertException(e);
}
return result;
}
示例6: search
import org.apache.lucene.search.Searcher; //导入方法依赖的package包/类
public SearchResult search(SearchCriteria criteria, List<MusicFolder> musicFolders, IndexType indexType) {
SearchResult result = new SearchResult();
int offset = criteria.getOffset();
int count = criteria.getCount();
result.setOffset(offset);
IndexReader reader = null;
try {
reader = createIndexReader(indexType);
Searcher searcher = new IndexSearcher(reader);
Analyzer analyzer = new SubsonicAnalyzer();
MultiFieldQueryParser queryParser = new MultiFieldQueryParser(LUCENE_VERSION, indexType.getFields(), analyzer, indexType.getBoosts());
BooleanQuery query = new BooleanQuery();
query.add(queryParser.parse(analyzeQuery(criteria.getQuery())), BooleanClause.Occur.MUST);
List<SpanTermQuery> musicFolderQueries = new ArrayList<SpanTermQuery>();
for (MusicFolder musicFolder : musicFolders) {
if (indexType == ALBUM_ID3 || indexType == ARTIST_ID3) {
musicFolderQueries.add(new SpanTermQuery(new Term(FIELD_FOLDER_ID, NumericUtils.intToPrefixCoded(musicFolder.getId()))));
} else {
musicFolderQueries.add(new SpanTermQuery(new Term(FIELD_FOLDER, musicFolder.getPath().getPath())));
}
}
query.add(new SpanOrQuery(musicFolderQueries.toArray(new SpanQuery[musicFolderQueries.size()])), BooleanClause.Occur.MUST);
TopDocs topDocs = searcher.search(query, null, offset + count);
result.setTotalHits(topDocs.totalHits);
int start = Math.min(offset, topDocs.totalHits);
int end = Math.min(start + count, topDocs.totalHits);
for (int i = start; i < end; i++) {
Document doc = searcher.doc(topDocs.scoreDocs[i].doc);
switch (indexType) {
case SONG:
case ARTIST:
case ALBUM:
MediaFile mediaFile = mediaFileService.getMediaFile(Integer.valueOf(doc.get(FIELD_ID)));
addIfNotNull(mediaFile, result.getMediaFiles());
break;
case ARTIST_ID3:
Artist artist = artistDao.getArtist(Integer.valueOf(doc.get(FIELD_ID)));
addIfNotNull(artist, result.getArtists());
break;
case ALBUM_ID3:
Album album = albumDao.getAlbum(Integer.valueOf(doc.get(FIELD_ID)));
addIfNotNull(album, result.getAlbums());
break;
default:
break;
}
}
} catch (Throwable x) {
LOG.error("Failed to execute Lucene search.", x);
} finally {
FileUtil.closeQuietly(reader);
}
return result;
}
示例7: generateConfidence
import org.apache.lucene.search.Searcher; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static Map<String, Float> generateConfidence(final String indexFolder, String query, final String field,
final int noOfPages, final String[] ignoreWordList) throws Exception {
Map<String, Float> docNameScore = new HashMap<String, Float>();
IndexReader reader = null;
Analyzer analyzer = null;
Searcher searcher = null;
try {
reader = IndexReader.open(FSDirectory.open(new File(indexFolder)), true); // only searching, so read-only=true
searcher = new IndexSearcher(reader);
analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
QueryParser parser = new QueryParser(Version.LUCENE_CURRENT, field, analyzer);
if (query != null) {
query = query.trim();
} else {
System.out.println("Wrong Query generated");
return null;
}
parser.setAllowLeadingWildcard(true);
BooleanQuery searchQuery = new BooleanQuery();
Query matchQuery = parser.parse(query);
searchQuery.add(matchQuery, BooleanClause.Occur.MUST);
if (ignoreWordList != null) {
for (String ignoreWord : ignoreWordList) {
TermQuery notMatchClause = new TermQuery(new Term(field, ignoreWord.toLowerCase()));
searchQuery.add(notMatchClause, BooleanClause.Occur.MUST_NOT);
}
}
ScoreDoc[] scoreDocs = doPagingSearch(searcher, searchQuery, noOfPages);
if (scoreDocs != null && scoreDocs.length > 0) {
for (int i = 0; i < scoreDocs.length; i++) {
Document document = searcher.doc(scoreDocs[i].doc);
docNameScore.put(document.get("rowId"), calculateConfidenceScore(scoreDocs[i].score));
}
}
} finally {
if (reader != null) {
reader.close();
}
if (analyzer != null) {
analyzer.close();
}
if (searcher != null) {
searcher.close();
}
}
return docNameScore;
}
示例8: search
import org.apache.lucene.search.Searcher; //导入方法依赖的package包/类
public SearchResult search(SearchCriteria criteria, IndexType indexType, int user_group_id) {
SearchResult result = new SearchResult();
int offset = criteria.getOffset();
int count = criteria.getCount();
result.setOffset(offset);
IndexReader reader = null;
try {
reader = createIndexReader(indexType);
Searcher searcher = new IndexSearcher(reader);
Analyzer analyzer = new SubsonicAnalyzer();
MultiFieldQueryParser queryParser = new MultiFieldQueryParser(LUCENE_VERSION, indexType.getFields(), analyzer, indexType.getBoosts());
queryParser.setAllowLeadingWildcard(true);
Query query = queryParser.parse(criteria.getQuery());
TopDocs topDocs = searcher.search(query, null, offset + count);
result.setTotalHits(topDocs.totalHits);
int start = Math.min(offset, topDocs.totalHits);
int end = Math.min(start + count, topDocs.totalHits);
for (int i = start; i < end; i++) {
Document doc = searcher.doc(topDocs.scoreDocs[i].doc);
switch (indexType) {
case SONG:
case ARTIST:
case ALBUM:
MediaFile mediaFile = mediaFileService.getMediaFile(Integer.valueOf(doc.get(FIELD_ID)), user_group_id);
addIfNotNull(mediaFile, result.getMediaFiles());
break;
case ARTIST_ID3:
Artist artist = artistDao.getArtist(Integer.valueOf(doc.get(FIELD_ID)));
addIfNotNull(artist, result.getArtists());
break;
case ALBUM_ID3:
Album album = albumDao.getAlbum(Integer.valueOf(doc.get(FIELD_ID)));
addIfNotNull(album, result.getAlbums());
break;
default:
break;
}
}
} catch (Throwable x) {
LOG.error("Failed to execute Lucene search.", x);
} finally {
FileUtil.closeQuietly(reader);
}
return result;
}
示例9: search
import org.apache.lucene.search.Searcher; //导入方法依赖的package包/类
public SearchResult search(SearchCriteria criteria, IndexType indexType, int user_group_id) {
SearchResult result = new SearchResult();
int offset = criteria.getOffset();
int count = criteria.getCount();
result.setOffset(offset);
IndexReader reader = null;
try {
reader = createIndexReader(indexType);
Searcher searcher = new IndexSearcher(reader);
Analyzer analyzer = new SubsonicAnalyzer();
MultiFieldQueryParser queryParser = new MultiFieldQueryParser(LUCENE_VERSION, indexType.getFields(), analyzer, indexType.getBoosts());
queryParser.setAllowLeadingWildcard(true);
Query query = queryParser.parse(criteria.getQuery());
// Query query = queryParser.parse(queryParser.escape(criteria.getQuery()));
TopDocs topDocs = searcher.search(query, null, offset + count);
result.setTotalHits(topDocs.totalHits);
int start = Math.min(offset, topDocs.totalHits);
int end = Math.min(start + count, topDocs.totalHits);
for (int i = start; i < end; i++) {
Document doc = searcher.doc(topDocs.scoreDocs[i].doc);
switch (indexType) {
case SONG:
case ARTIST:
case ALBUM:
MediaFile mediaFile = mediaFileService.getMediaFile(Integer.valueOf(doc.get(FIELD_ID)), user_group_id);
addIfNotNull(mediaFile, result.getMediaFiles());
break;
case ARTIST_ID3:
Artist artist = artistDao.getArtist(Integer.valueOf(doc.get(FIELD_ID)));
addIfNotNull(artist, result.getArtists());
break;
case ALBUM_ID3:
Album album = albumDao.getAlbum(Integer.valueOf(doc.get(FIELD_ID)));
addIfNotNull(album, result.getAlbums());
break;
default:
break;
}
}
} catch (Throwable x) {
LOG.error("Failed to execute Lucene search.", x);
} finally {
FileUtil.closeQuietly(reader);
}
return result;
}