本文整理汇总了Java中org.hibernate.search.indexes.IndexReaderAccessor类的典型用法代码示例。如果您正苦于以下问题:Java IndexReaderAccessor类的具体用法?Java IndexReaderAccessor怎么用?Java IndexReaderAccessor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IndexReaderAccessor类属于org.hibernate.search.indexes包,在下文中一共展示了IndexReaderAccessor类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateQuery
import org.hibernate.search.indexes.IndexReaderAccessor; //导入依赖的package包/类
/**
* Generates a lucene query to search for a given term in all the indexed fields of a class
*
* @param searchTerm the term to search for
* @param searchedEntity the class searched
* @param sess the hibernate session
* @param defaultAnalyzer the default analyzer for parsing the search terms
* @return
* @throws ParseException
*/
public static Query generateQuery(String searchTerm, Class searchedEntity, Session sess, Analyzer defaultAnalyzer) throws ParseException {
Query qry = null;
if (searchTerm.equals("*")) {
qry = new MatchAllDocsQuery();
} else {
// Search in all indexed fields
IndexReaderAccessor readerAccessor = null;
IndexReader reader = null;
try {
FullTextSession txtSession = Search.getFullTextSession(sess);
// obtain analyzer to parse the query:
Analyzer analyzer;
if (searchedEntity == null) {
analyzer = defaultAnalyzer;
} else {
analyzer = txtSession.getSearchFactory().getAnalyzer(searchedEntity);
}
// search on all indexed fields: generate field list, removing internal hibernate search field name: _hibernate_class
// TODO: possible improvement: cache the fields of each entity
SearchFactory searchFactory = txtSession.getSearchFactory();
readerAccessor = searchFactory.getIndexReaderAccessor();
reader = readerAccessor.open(searchedEntity);
Collection<String> fieldNames = reader.getFieldNames(IndexReader.FieldOption.INDEXED);
fieldNames.remove("_hibernate_class");
String[] fnames = new String[0];
fnames = fieldNames.toArray(fnames);
// To search on all fields, search the term in all fields
String[] queries = new String[fnames.length];
for (int i = 0; i < queries.length; ++i) {
queries[i] = searchTerm;
}
qry = MultiFieldQueryParser.parse(Version.LUCENE_35, queries, fnames, analyzer);
} finally {
if (readerAccessor != null && reader != null) {
readerAccessor.close(reader);
}
}
}
return qry;
}
示例2: getIndexReaderAccessor
import org.hibernate.search.indexes.IndexReaderAccessor; //导入依赖的package包/类
@Override
public IndexReaderAccessor getIndexReaderAccessor() {
return this.searchFactory.getIndexReaderAccessor();
}
示例3: getIndexReaderAccessor
import org.hibernate.search.indexes.IndexReaderAccessor; //导入依赖的package包/类
@Override
public IndexReaderAccessor getIndexReaderAccessor() {
return this.searchIntegrator.getIndexReaderAccessor();
}
示例4: getIndexReaderAccessor
import org.hibernate.search.indexes.IndexReaderAccessor; //导入依赖的package包/类
/**
* Provides access to the IndexReader API
*
* @return the IndexReaderAccessor for this SearchFactory
*/
IndexReaderAccessor getIndexReaderAccessor();