当前位置: 首页>>代码示例>>Java>>正文


Java IndexReaderAccessor类代码示例

本文整理汇总了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;
}
 
开发者ID:SMVBE,项目名称:ldadmin,代码行数:57,代码来源:HibernateSearchTools.java

示例2: getIndexReaderAccessor

import org.hibernate.search.indexes.IndexReaderAccessor; //导入依赖的package包/类
@Override
public IndexReaderAccessor getIndexReaderAccessor() {
	return this.searchFactory.getIndexReaderAccessor();
}
 
开发者ID:Hotware,项目名称:Hibernate-Search-GenericJPA,代码行数:5,代码来源:JPASearchFactoryAdapter.java

示例3: getIndexReaderAccessor

import org.hibernate.search.indexes.IndexReaderAccessor; //导入依赖的package包/类
@Override
public IndexReaderAccessor getIndexReaderAccessor() {
	return this.searchIntegrator.getIndexReaderAccessor();
}
 
开发者ID:Hotware,项目名称:Hibernate-Search-GenericJPA,代码行数:5,代码来源:StandaloneSearchFactoryImpl.java

示例4: getIndexReaderAccessor

import org.hibernate.search.indexes.IndexReaderAccessor; //导入依赖的package包/类
/**
 * Provides access to the IndexReader API
 *
 * @return the IndexReaderAccessor for this SearchFactory
 */
IndexReaderAccessor getIndexReaderAccessor();
 
开发者ID:Hotware,项目名称:Hibernate-Search-GenericJPA,代码行数:7,代码来源:SearchFactory.java


注:本文中的org.hibernate.search.indexes.IndexReaderAccessor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。