@ -250,7 +250,7 @@ public final class QueryParams {
this . constraint = constraint ;
this . allofconstraint = allofconstraint ;
this . siteexcludes = siteexcludes ! = null & & siteexcludes . isEmpty ( ) ? null : siteexcludes ;
this . snippetCacheStrategy = snippetCacheStrategy;
this . snippetCacheStrategy = contentdom = = ContentDomain . TEXT ? snippetCacheStrategy : contentdom = = null ? null : CacheStrategy . CACHEONLY ;
this . clienthost = host ;
this . remotepeer = null ;
this . starttime = Long . valueOf ( System . currentTimeMillis ( ) ) ;
@ -376,27 +376,125 @@ public final class QueryParams {
return SetTools . anymatch ( wordhashes , keyhashes ) ;
}
public SolrQuery solrQuery ( boolean getFacets ) {
public SolrQuery solrQuery ( ContentDomain cd , boolean getFacets ) {
if ( cd = = ContentDomain . IMAGE ) return solrImageQuery ( getFacets ) ;
return solrTextQuery ( getFacets ) ;
}
private SolrQuery solrTextQuery ( boolean getFacets ) {
if ( this . cachedQuery ! = null ) {
this . cachedQuery . setStart ( this . offset ) ;
return this . cachedQuery ;
}
if ( this . queryGoal . getIncludeStrings ( ) . size ( ) = = 0 ) return null ;
// construct query
final SolrQuery params = new SolrQuery ( ) ;
final SolrQuery params = getBasicParams ( getFacets ) ;
int rankingProfile = this . ranking . coeff_date = = RankingProfile . COEFF_MAX ? 1 : ( this . modifier . sitehash ! = null | | this . modifier . sitehost ! = null ) ? 2 : 0 ;
params . setQuery ( this . queryGoal . collectionQueryString ( this . indexSegment . fulltext ( ) . getDefaultConfiguration ( ) , rankingProfile ) . toString ( ) ) ;
params . setParam ( "defType" , "edismax" ) ;
params . setQuery ( this . queryGoal . collectionTextQueryString ( this . indexSegment . fulltext ( ) . getDefaultConfiguration ( ) , rankingProfile ) . toString ( ) ) ;
Ranking ranking = indexSegment . fulltext ( ) . getDefaultConfiguration ( ) . getRanking ( rankingProfile ) ; // for a by-date ranking select different ranking profile
String bq = ranking . getBoostQuery ( ) ;
String bf = ranking . getBoostFunction ( ) ;
if ( bq . length ( ) > 0 ) params . setParam ( "bq" , bq ) ;
if ( bf . length ( ) > 0 ) params . setParam ( "boost" , bf ) ; // a boost function extension, see http://wiki.apache.org/solr/ExtendedDisMax#bf_.28Boost_Function.2C_additive.29
/ *
if ( this . contentdom = = ContentDomain . IMAGE ) {
fq . append ( " AND (" ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"jpg\"" ) ;
fq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"tif\"" ) ;
fq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"tiff\"" ) ;
fq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"png\")" ) ;
}
if ( this . contentdom = = ContentDomain . AUDIO ) {
fq . append ( " AND (" ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"aif\"" ) ;
fq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"aiff\"" ) ;
fq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"mp3\"" ) ;
fq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"ogg\")" ) ;
}
if ( this . contentdom = = ContentDomain . VIDEO ) {
fq . append ( " AND (" ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"mpg\"" ) ;
fq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"avi\"" ) ;
fq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"mp4\"" ) ;
fq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"mkv\")" ) ;
}
if ( this . contentdom = = ContentDomain . APP ) {
fq . append ( " AND (" ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"apk\"" ) ;
fq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"exe\"" ) ;
fq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"dmg\"" ) ;
fq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"gz\")" ) ;
}
* /
// prepare result
ConcurrentLog . info ( "Protocol" , "SOLR QUERY: " + params . toString ( ) ) ;
this . cachedQuery = params ;
return params ;
}
private SolrQuery solrImageQuery ( boolean getFacets ) {
if ( this . cachedQuery ! = null ) {
this . cachedQuery . setStart ( this . offset ) ;
return this . cachedQuery ;
}
if ( this . queryGoal . getIncludeStrings ( ) . size ( ) = = 0 ) return null ;
// construct query
final SolrQuery params = getBasicParams ( getFacets ) ;
params . setQuery ( this . queryGoal . collectionImageQueryString ( ) . toString ( ) ) ;
// set boosts
StringBuilder bq = new StringBuilder ( ) ;
bq . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"jpg\"" ) ;
bq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"tif\"" ) ;
bq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"tiff\"" ) ;
bq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"png\"" ) ;
params . setParam ( "bq" , bq . toString ( ) ) ;
// prepare result
ConcurrentLog . info ( "Protocol" , "SOLR QUERY: " + params . toString ( ) ) ;
this . cachedQuery = params ;
return params ;
}
private SolrQuery getBasicParams ( boolean getFacets ) {
final SolrQuery params = new SolrQuery ( ) ;
params . setParam ( "defType" , "edismax" ) ;
params . setStart ( this . offset ) ;
params . setRows ( this . itemsPerPage ) ;
params . setFacet ( false ) ;
if ( this . ranking . coeff_date = = RankingProfile . COEFF_MAX ) {
// set a most-recent ordering
params . setSort ( new SortClause ( CollectionSchema . last_modified . getSolrFieldName ( ) , SolrQuery . ORDER . desc ) ) ;
//params.setSortField(CollectionSchema.last_modified.getSolrFieldName(), ORDER.desc); // deprecated in Solr 4.2
}
// add site facets
final String fq = getFacets ( ) ;
if ( fq . length ( ) > 0 ) {
params . setFilterQueries ( fq ) ;
}
// set facet query attributes
if ( getFacets & & this . facetfields . size ( ) > 0 ) {
params . setFacet ( true ) ;
params . setFacetLimit ( this . maxfacets ) ;
params . setFacetSort ( FacetParams . FACET_SORT_COUNT ) ;
params . setParam ( FacetParams . FACET_METHOD , FacetParams . FACET_METHOD_fcs ) ;
for ( String field : this . facetfields ) params . addFacetField ( field ) ;
} else {
params . setFacet ( false ) ;
}
params . setFields ( "*" , "score" ) ; // we need the score for post-ranking
return params ;
}
private String getFacets ( ) {
// add site facets
final StringBuilder fq = new StringBuilder ( ) ;
if ( this . modifier . sitehash = = null & & this . modifier . sitehost = = null ) {
@ -441,34 +539,6 @@ public final class QueryParams {
fq . append ( " AND " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"" ) . append ( this . modifier . filetype ) . append ( '\"' ) ;
}
if ( this . contentdom = = ContentDomain . IMAGE ) {
fq . append ( " AND (" ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"jpg\"" ) ;
fq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"tif\"" ) ;
fq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"tiff\"" ) ;
fq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"png\")" ) ;
}
if ( this . contentdom = = ContentDomain . AUDIO ) {
fq . append ( " AND (" ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"aif\"" ) ;
fq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"aiff\"" ) ;
fq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"mp3\"" ) ;
fq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"ogg\")" ) ;
}
if ( this . contentdom = = ContentDomain . VIDEO ) {
fq . append ( " AND (" ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"mpg\"" ) ;
fq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"avi\"" ) ;
fq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"mp4\"" ) ;
fq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"mkv\")" ) ;
}
if ( this . contentdom = = ContentDomain . APP ) {
fq . append ( " AND (" ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"apk\"" ) ;
fq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"exe\"" ) ;
fq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"dmg\"" ) ;
fq . append ( " OR " ) . append ( CollectionSchema . url_file_ext_s . getSolrFieldName ( ) ) . append ( ":\"gz\")" ) ;
}
if ( this . inlink ! = null ) {
fq . append ( " AND " ) . append ( CollectionSchema . outboundlinks_urlstub_sxt . getSolrFieldName ( ) ) . append ( ":\"" ) . append ( this . inlink ) . append ( '\"' ) ;
}
@ -495,43 +565,13 @@ public final class QueryParams {
//params.set("d", GeoLocation.degreeToKm(this.radius));
fq . append ( " AND " ) . append ( "{!bbox sfield=" + CollectionSchema . coordinate_p . getSolrFieldName ( ) + " pt=" + Double . toString ( this . lat ) + "," + Double . toString ( this . lon ) + " d=" + GeoLocation . degreeToKm ( this . radius ) + "}" ) ;
//params.setRows(Integer.MAX_VALUE);
} else {
// set ranking
if ( this . ranking . coeff_date = = RankingProfile . COEFF_MAX ) {
// set a most-recent ordering
params . setSort ( new SortClause ( CollectionSchema . last_modified . getSolrFieldName ( ) , SolrQuery . ORDER . desc ) ) ;
//params.setSortField(CollectionSchema.last_modified.getSolrFieldName(), ORDER.desc); // deprecated in Solr 4.2
}
}
if ( this . modifier . collection ! = null & & this . modifier . collection . length ( ) > 0 ) {
fq . append ( " AND " ) . append ( QueryModifier . parseCollectionExpression ( this . modifier . collection ) ) ;
}
if ( fq . length ( ) > 0 ) {
params . setFilterQueries ( fq . substring ( 5 ) ) ;
}
params . setStart ( offset ) ;
params . setRows ( itemsPerPage ) ;
// set facet query attributes
if ( getFacets & & this . facetfields . size ( ) > 0 ) {
params . setFacet ( true ) ;
params . setFacetLimit ( this . maxfacets ) ;
params . setFacetSort ( FacetParams . FACET_SORT_COUNT ) ;
params . setParam ( FacetParams . FACET_METHOD , FacetParams . FACET_METHOD_fcs ) ;
for ( String field : this . facetfields ) params . addFacetField ( field ) ;
} else {
params . setFacet ( false ) ;
}
params . setFields ( "*" , "score" ) ; // we need the score for post-ranking
// prepare result
ConcurrentLog . info ( "Protocol" , "SOLR QUERY: " + params . toString ( ) ) ;
this . cachedQuery = params ;
return params ;
return fq . length ( ) > 0 ? fq . substring ( 5 ) : fq . toString ( ) ;
}
public QueryGoal getQueryGoal ( ) {