本文整理匯總了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();