| Method from org.hibernate.search.query.FullTextQueryImpl Detail: |
public void disableFullTextFilter(String name) {
filterDefinitions.remove( name );
}
|
public FullTextFilter enableFullTextFilter(String name) {
if ( filterDefinitions == null ) {
filterDefinitions = new HashMap< String, FullTextFilterImpl >();
}
FullTextFilterImpl filterDefinition = filterDefinitions.get( name );
if ( filterDefinition != null ) return filterDefinition;
filterDefinition = new FullTextFilterImpl();
filterDefinition.setName( name );
FilterDef filterDef = getSearchFactoryImplementor().getFilterDefinition( name );
if ( filterDef == null ) {
throw new SearchException( "Unkown @FullTextFilter: " + name );
}
filterDefinitions.put( name, filterDefinition );
return filterDefinition;
}
|
public int executeUpdate() throws HibernateException {
throw new HibernateException( "Not supported operation" );
}
|
public Explanation explain(int documentId) {
Explanation explanation = null;
SearchFactoryImplementor searchFactoryImplementor = getSearchFactoryImplementor();
Searcher searcher = buildSearcher( searchFactoryImplementor );
if (searcher == null) {
throw new SearchException("Unable to build explanation for document id:"
+ documentId + ". no index found");
}
try {
org.apache.lucene.search.Query query = filterQueryByClasses( luceneQuery );
buildFilters();
explanation = searcher.explain( query, documentId );
}
catch (IOException e) {
throw new HibernateException( "Unable to query Lucene index and build explanation", e );
}
finally {
//searcher cannot be null
try {
closeSearcher( searcher, searchFactoryImplementor.getReaderProvider() );
}
catch (SearchException e) {
log.warn( "Unable to properly close searcher during lucene query: " + getQueryString(), e );
}
}
return explanation;
}
|
protected Map getLockModes() {
return null;
}
|
public int getResultSize() {
if ( resultSize == null ) {
//get result size without object initialization
SearchFactoryImplementor searchFactoryImplementor = ContextHelper.getSearchFactoryBySFI( session );
IndexSearcher searcher = buildSearcher( searchFactoryImplementor );
if ( searcher == null ) {
resultSize = 0;
}
else {
Hits hits;
try {
hits = getQueryAndHits( searcher ).hits;
resultSize = hits.length();
}
catch (IOException e) {
throw new HibernateException( "Unable to query Lucene index", e );
}
finally {
//searcher cannot be null
try {
closeSearcher( searcher, searchFactoryImplementor.getReaderProvider() );
//searchFactoryImplementor.getReaderProvider().closeReader( searcher.getIndexReader() );
}
catch (SearchException e) {
log.warn( "Unable to properly close searcher during lucene query: " + getQueryString(), e );
}
}
}
}
return this.resultSize;
}
|
public Iterator iterate() throws HibernateException {
//implement an interator which keep the id/class for each hit and get the object on demand
//cause I can't keep the searcher and hence the hit opened. I dont have any hook to know when the
//user stop using it
//scrollable is better in this area
SearchFactoryImplementor searchFactoryImplementor = ContextHelper.getSearchFactoryBySFI( session );
//find the directories
IndexSearcher searcher = buildSearcher( searchFactoryImplementor );
if ( searcher == null ) {
return new IteratorImpl( Collections.EMPTY_LIST, noLoader );
}
try {
QueryAndHits queryAndHits = getQueryAndHits( searcher );
int first = first();
int max = max( first, queryAndHits.hits );
Session sess = (Session) this.session;
int size = max - first + 1 < 0 ? 0 : max - first + 1;
List< EntityInfo > infos = new ArrayList< EntityInfo >( size );
DocumentExtractor extractor = new DocumentExtractor( queryAndHits.preparedQuery, searcher, searchFactoryImplementor, indexProjection );
for (int index = first; index < = max; index++) {
//TODO use indexSearcher.getIndexReader().document( hits.id(index), FieldSelector(indexProjection) );
infos.add( extractor.extract( queryAndHits.hits, index ) );
}
Loader loader = getLoader( sess, searchFactoryImplementor );
return new IteratorImpl( infos, loader );
}
catch (IOException e) {
throw new HibernateException( "Unable to query Lucene index", e );
}
finally {
try {
closeSearcher( searcher, searchFactoryImplementor.getReaderProvider() );
}
catch (SearchException e) {
log.warn( "Unable to properly close searcher during lucene query: " + getQueryString(), e );
}
}
}
Return an interator on the results.
Retrieve the object one by one (initialize it during the next() operation) |
public List list() throws HibernateException {
SearchFactoryImplementor searchFactoryImplementor = ContextHelper.getSearchFactoryBySFI( session );
//find the directories
IndexSearcher searcher = buildSearcher( searchFactoryImplementor );
if ( searcher == null ) return Collections.EMPTY_LIST;
try {
QueryAndHits queryAndHits = getQueryAndHits( searcher );
int first = first();
int max = max( first, queryAndHits.hits );
Session sess = (Session) this.session;
int size = max - first + 1 < 0 ? 0 : max - first + 1;
List< EntityInfo > infos = new ArrayList< EntityInfo >( size );
DocumentExtractor extractor = new DocumentExtractor( queryAndHits.preparedQuery, searcher, searchFactoryImplementor, indexProjection );
for (int index = first; index < = max; index++) {
infos.add( extractor.extract( queryAndHits.hits, index ) );
}
Loader loader = getLoader( sess, searchFactoryImplementor );
List list = loader.load( infos.toArray( new EntityInfo[infos.size()] ) );
if ( resultTransformer == null || loader instanceof ProjectionLoader ) {
//stay consistent with transformTuple which can only be executed during a projection
return list;
}
else {
return resultTransformer.transformList( list );
}
}
catch (IOException e) {
throw new HibernateException( "Unable to query Lucene index", e );
}
finally {
try {
closeSearcher( searcher, searchFactoryImplementor.getReaderProvider() );
}
catch (SearchException e) {
log.warn( "Unable to properly close searcher during lucene query: " + getQueryString(), e );
}
}
}
|
public ScrollableResults scroll() throws HibernateException {
//keep the searcher open until the resultset is closed
SearchFactoryImplementor searchFactory = ContextHelper.getSearchFactoryBySFI( session );
//find the directories
IndexSearcher searcher = buildSearcher( searchFactory );
//FIXME: handle null searcher
try {
QueryAndHits queryAndHits = getQueryAndHits( searcher );
int first = first();
int max = max( first, queryAndHits.hits );
DocumentExtractor extractor = new DocumentExtractor( queryAndHits.preparedQuery, searcher, searchFactory, indexProjection );
Loader loader = getLoader( (Session) this.session, searchFactory );
return new ScrollableResultsImpl( searcher, queryAndHits.hits, first, max, fetchSize, extractor, loader, searchFactory );
}
catch (IOException e) {
//close only in case of exception
try {
closeSearcher( searcher, searchFactory.getReaderProvider() );
}
catch (SearchException ee) {
//we have the initial issue already
}
throw new HibernateException( "Unable to query Lucene index", e );
}
}
|
public ScrollableResults scroll(ScrollMode scrollMode) throws HibernateException {
//TODO think about this scrollmode
return scroll();
}
|
public FullTextQuery setCriteriaQuery(Criteria criteria) {
this.criteria = criteria;
return this;
}
|
public FullTextQuery setFetchSize(int fetchSize) {
super.setFetchSize( fetchSize );
if ( fetchSize < = 0 ) {
throw new IllegalArgumentException( "'fetch size' parameter less than or equals to 0" );
}
this.fetchSize = fetchSize;
return this;
}
|
public FullTextQuery setFilter(Filter filter) {
this.filter = filter;
return this;
}
|
public FullTextQuery setFirstResult(int firstResult) {
if ( firstResult < 0 ) {
throw new IllegalArgumentException( "'first' pagination parameter less than 0" );
}
this.firstResult = firstResult;
return this;
}
|
public Query setLockMode(String alias,
LockMode lockMode) {
return null;
}
|
public FullTextQuery setMaxResults(int maxResults) {
if ( maxResults < 0 ) {
throw new IllegalArgumentException( "'max' pagination parameter less than 0" );
}
this.maxResults = maxResults;
return this;
}
|
public FullTextQuery setProjection(String fields) {
if ( fields == null || fields.length == 0 ) {
this.indexProjection = null;
}
else {
this.indexProjection = fields;
}
return this;
}
|
public FullTextQuery setResultTransformer(ResultTransformer transformer) {
super.setResultTransformer( transformer );
this.resultTransformer = transformer;
return this;
}
|
public FullTextQuery setSort(Sort sort) {
this.sort = sort;
return this;
}
|