int size = fieldsContext.size(); Map<String,Map<String, Int>> termFreqMapPerFieldname = new HashMap<String,Map<String, Int>>( size ); final Fields vectors;
int size = fieldsContext.size(); Map<String,Map<String, Int>> termFreqMapPerFieldname = new HashMap<String,Map<String, Int>>( size ); final Fields vectors;
/** * Create the More Like This query from a PriorityQueue */ private Query createQuery(List<PriorityQueue<Object[]>> q) { //In the original algorithm, the number of terms is limited to maxQueryTerms //In the current implementation, we do nbrOfFields * maxQueryTerms int length = fieldsContext.size(); if ( length == 0 ) { throw new AssertionFailure( "Querying MoreLikeThis on 0 field." ); } else if ( length == 1 ) { return createQuery( q.get( 0 ), fieldsContext.getFirst() ); } else { BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder(); //the fieldsContext indexes are aligned with the priority queue's Iterator<FieldContext> fieldsContextIterator = fieldsContext.iterator(); for ( PriorityQueue<Object[]> queue : q ) { try { queryBuilder.add( createQuery( queue, fieldsContextIterator.next() ), BooleanClause.Occur.SHOULD ); } catch (BooleanQuery.TooManyClauses ignore) { break; } } return queryBuilder.build(); } }
/** * Create the More Like This query from a PriorityQueue */ private Query createQuery(List<PriorityQueue<Object[]>> q) { //In the original algorithm, the number of terms is limited to maxQueryTerms //In the current implementation, we do nbrOfFields * maxQueryTerms int length = fieldsContext.size(); if ( length == 0 ) { throw new AssertionFailure( "Querying MoreLikeThis on 0 field." ); } else if ( length == 1 ) { return createQuery( q.get( 0 ), fieldsContext.getFirst() ); } else { BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder(); //the fieldsContext indexes are aligned with the priority queue's Iterator<FieldContext> fieldsContextIterator = fieldsContext.iterator(); for ( PriorityQueue<Object[]> queue : q ) { try { queryBuilder.add( createQuery( queue, fieldsContextIterator.next() ), BooleanClause.Occur.SHOULD ); } catch (BooleanQuery.TooManyClauses ignore) { break; } } return queryBuilder.build(); } }
@Override public Query createQuery() { final int size = fieldsContext.size(); final ConversionContext conversionContext = new ContextualExceptionBridgeHelper(); if ( size == 1 ) { return queryCustomizer.setWrappedQuery( createQuery( fieldsContext.getFirst(), conversionContext ) ).createQuery(); } else { BooleanQuery.Builder aggregatedFieldsQueryBuilder = new BooleanQuery.Builder(); for ( FieldContext fieldContext : fieldsContext ) { aggregatedFieldsQueryBuilder.add( createQuery( fieldContext, conversionContext ), BooleanClause.Occur.SHOULD ); } BooleanQuery aggregatedFieldsQuery = aggregatedFieldsQueryBuilder.build(); return queryCustomizer.setWrappedQuery( aggregatedFieldsQuery ).createQuery(); } }
@Override public Query createQuery() { final int size = fieldsContext.size(); final ConversionContext conversionContext = new ContextualExceptionBridgeHelper(); if ( size == 1 ) { FieldContext fieldContext = fieldsContext.getFirst(); return queryCustomizer.setWrappedQuery( fieldContext.getFieldCustomizer().setWrappedQuery( createQuery( fieldContext, conversionContext ) ).createQuery() ).createQuery(); } else { BooleanQuery.Builder aggregatedFieldsQueryBuilder = new BooleanQuery.Builder(); for ( FieldContext fieldContext : fieldsContext ) { aggregatedFieldsQueryBuilder.add( fieldContext.getFieldCustomizer().setWrappedQuery( createQuery( fieldContext, conversionContext ) ) .createQuery(), BooleanClause.Occur.SHOULD ); } BooleanQuery aggregatedFieldsQuery = aggregatedFieldsQueryBuilder.build(); return queryCustomizer.setWrappedQuery( aggregatedFieldsQuery ).createQuery(); } }
public Query createQuery() { Query query; final ExtendedSearchIntegrator searchIntegrator = queryContext.getExtendedSearchIntegrator(); final DocumentBuilderIndexedEntity documentBuilder = queryContext.getDocumentBuilder(); IndexReader indexReader = searchIntegrator.getIndexReaderAccessor().open( queryContext.getEntityType().asTypeSet() ); // retrieving the docId and building the more like this query form the term vectors must be using the same index reader try { String[] fieldNames = getAllCompatibleFieldNames( documentBuilder ); if ( fieldsContext.size() == 0 ) { // Use all compatible fields when comparingAllFields is used fieldsContext.addAll( fieldNames ); } query = new MoreLikeThisBuilder( documentBuilder, searchIntegrator ) .compatibleFieldNames( fieldNames ) .fieldsContext( fieldsContext ) .queryContext( queryContext ) .indexReader( indexReader ) .inputType( inputType ) .input( input ) .otherMoreLikeThisContext( moreLikeThisContext ) .createQuery(); } finally { searchIntegrator.getIndexReaderAccessor().close( indexReader ); } //TODO implement INPUT_TYPE.READER //TODO implement INPUT_TYPE.STRING return queryCustomizer.setWrappedQuery( query ).createQuery(); }
public Query createQuery() { Query query; final ExtendedSearchIntegrator searchIntegrator = queryContext.getExtendedSearchIntegrator(); final DocumentBuilderIndexedEntity documentBuilder = queryContext.getDocumentBuilder(); IndexReader indexReader = searchIntegrator.getIndexReaderAccessor().open( queryContext.getEntityType().asTypeSet() ); // retrieving the docId and building the more like this query form the term vectors must be using the same index reader try { String[] fieldNames = getAllCompatibleFieldNames( documentBuilder ); if ( fieldsContext.size() == 0 ) { // Use all compatible fields when comparingAllFields is used fieldsContext.addAll( fieldNames ); } query = new MoreLikeThisBuilder( documentBuilder, searchIntegrator ) .compatibleFieldNames( fieldNames ) .fieldsContext( fieldsContext ) .queryContext( queryContext ) .indexReader( indexReader ) .inputType( inputType ) .input( input ) .otherMoreLikeThisContext( moreLikeThisContext ) .createQuery(); } finally { searchIntegrator.getIndexReaderAccessor().close( indexReader ); } //TODO implement INPUT_TYPE.READER //TODO implement INPUT_TYPE.STRING return queryCustomizer.setWrappedQuery( query ).createQuery(); }