本文整理汇总了Java中org.apache.lucene.queryParser.MultiFieldQueryParser.setAllowLeadingWildcard方法的典型用法代码示例。如果您正苦于以下问题:Java MultiFieldQueryParser.setAllowLeadingWildcard方法的具体用法?Java MultiFieldQueryParser.setAllowLeadingWildcard怎么用?Java MultiFieldQueryParser.setAllowLeadingWildcard使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.queryParser.MultiFieldQueryParser
的用法示例。
在下文中一共展示了MultiFieldQueryParser.setAllowLeadingWildcard方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createFullTextQuery
import org.apache.lucene.queryParser.MultiFieldQueryParser; //导入方法依赖的package包/类
private org.apache.lucene.search.Query createFullTextQuery(final String[] searchFields, final QueryFilter queryFilter,
final String searchString)
{
final MultiFieldQueryParser parser = new MultiFieldQueryParser(LUCENE_VERSION, searchFields, new ClassicAnalyzer(Version.LUCENE_31));
parser.setAllowLeadingWildcard(true);
org.apache.lucene.search.Query query = null;
try {
query = parser.parse(searchString);
} catch (final org.apache.lucene.queryParser.ParseException ex) {
final String errorMsg = "Lucene error message: "
+ ex.getMessage()
+ " (for "
+ this.getClass().getSimpleName()
+ ": "
+ searchString
+ ").";
if (queryFilter != null) {
queryFilter.setErrorMessage(errorMsg);
}
log.info(errorMsg);
return null;
}
return query;
}
示例2: search
import org.apache.lucene.queryParser.MultiFieldQueryParser; //导入方法依赖的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;
}
示例3: search
import org.apache.lucene.queryParser.MultiFieldQueryParser; //导入方法依赖的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;
}