@ -153,9 +153,9 @@ public class MirrorSolrConnector extends AbstractSolrConnector implements SolrCo
}
}
@Override
@Override
public SolrDocument get ById( final String key , final String . . . fields ) throws IOException {
public SolrDocument get Document ById( final String key , final String . . . fields ) throws IOException {
SolrDocument doc ;
SolrDocument doc ;
if ( ( solr0 ! = null & & ( ( doc = solr0 . get ById( key , fields ) ) ! = null ) ) | | ( solr1 ! = null & & ( ( doc = solr1 . ge tById( key , fields ) ) ! = null ) ) ) {
if ( ( solr0 ! = null & & ( ( doc = solr0 . get Document ById( key , fields ) ) ! = null ) ) | | ( solr1 ! = null & & ( ( doc = solr1 . ge tDocumen tById( key , fields ) ) ! = null ) ) ) {
return doc ;
return doc ;
}
}
return null ;
return null ;
@ -185,48 +185,48 @@ public class MirrorSolrConnector extends AbstractSolrConnector implements SolrCo
* @throws IOException
* @throws IOException
* /
* /
@Override
@Override
public SolrDocumentList q uery( final String querystring , final int offset , final int count , final String . . . fields ) throws IOException {
public SolrDocumentList getDocumentListByQ uery( final String querystring , final int offset , final int count , final String . . . fields ) throws IOException {
if ( this . solr0 = = null & & this . solr1 = = null ) return new SolrDocumentList ( ) ;
if ( this . solr0 = = null & & this . solr1 = = null ) return new SolrDocumentList ( ) ;
if ( offset = = 0 & & count = = 1 & & querystring . startsWith ( "id:" ) ) {
if ( offset = = 0 & & count = = 1 & & querystring . startsWith ( "id:" ) ) {
final SolrDocumentList list = new SolrDocumentList ( ) ;
final SolrDocumentList list = new SolrDocumentList ( ) ;
SolrDocument doc = get ById( querystring . charAt ( 3 ) = = '"' ? querystring . substring ( 4 , querystring . length ( ) - 1 ) : querystring . substring ( 3 ) , fields ) ;
SolrDocument doc = get Document ById( querystring . charAt ( 3 ) = = '"' ? querystring . substring ( 4 , querystring . length ( ) - 1 ) : querystring . substring ( 3 ) , fields ) ;
list . add ( doc ) ;
list . add ( doc ) ;
// no addToCache(list) here because that was already handlet in get();
// no addToCache(list) here because that was already handlet in get();
return list ;
return list ;
}
}
if ( this . solr0 ! = null & & this . solr1 = = null ) {
if ( this . solr0 ! = null & & this . solr1 = = null ) {
SolrDocumentList list = this . solr0 . q uery( querystring , offset , count , fields ) ;
SolrDocumentList list = this . solr0 . getDocumentListByQ uery( querystring , offset , count , fields ) ;
return list ;
return list ;
}
}
if ( this . solr1 ! = null & & this . solr0 = = null ) {
if ( this . solr1 ! = null & & this . solr0 = = null ) {
SolrDocumentList list = this . solr1 . q uery( querystring , offset , count , fields ) ;
SolrDocumentList list = this . solr1 . getDocumentListByQ uery( querystring , offset , count , fields ) ;
return list ;
return list ;
}
}
// combine both lists
// combine both lists
SolrDocumentList l ;
SolrDocumentList l ;
l = this . solr0 . q uery( querystring , offset , count , fields ) ;
l = this . solr0 . getDocumentListByQ uery( querystring , offset , count , fields ) ;
if ( l . size ( ) > = count ) return l ;
if ( l . size ( ) > = count ) return l ;
// at this point we need to know how many results are in solr0
// at this point we need to know how many results are in solr0
// compute this with a very bad hack; replace with better method later
// compute this with a very bad hack; replace with better method later
int size0 = 0 ;
int size0 = 0 ;
{ //bad hack - TODO: replace
{ //bad hack - TODO: replace
SolrDocumentList lHack = this . solr0 . q uery( querystring , 0 , Integer . MAX_VALUE , fields ) ;
SolrDocumentList lHack = this . solr0 . getDocumentListByQ uery( querystring , 0 , Integer . MAX_VALUE , fields ) ;
size0 = lHack . size ( ) ;
size0 = lHack . size ( ) ;
}
}
// now use the size of the first query to do a second query
// now use the size of the first query to do a second query
final SolrDocumentList list = new SolrDocumentList ( ) ;
final SolrDocumentList list = new SolrDocumentList ( ) ;
for ( final SolrDocument d : l ) list . add ( d ) ;
for ( final SolrDocument d : l ) list . add ( d ) ;
l = this . solr1 . q uery( querystring , offset + l . size ( ) - size0 , count - l . size ( ) , fields ) ;
l = this . solr1 . getDocumentListByQ uery( querystring , offset + l . size ( ) - size0 , count - l . size ( ) , fields ) ;
for ( final SolrDocument d : l ) list . add ( d ) ;
for ( final SolrDocument d : l ) list . add ( d ) ;
return list ;
return list ;
}
}
@Override
@Override
public QueryResponse query ( ModifiableSolrParams query ) throws IOException , SolrException {
public QueryResponse getResponseByParams ( ModifiableSolrParams query ) throws IOException , SolrException {
Integer count0 = query . getInt ( CommonParams . ROWS ) ;
Integer count0 = query . getInt ( CommonParams . ROWS ) ;
int count = count0 = = null ? 10 : count0 . intValue ( ) ;
int count = count0 = = null ? 10 : count0 . intValue ( ) ;
Integer start0 = query . getInt ( CommonParams . START ) ;
Integer start0 = query . getInt ( CommonParams . START ) ;
@ -234,16 +234,16 @@ public class MirrorSolrConnector extends AbstractSolrConnector implements SolrCo
if ( this . solr0 = = null & & this . solr1 = = null ) return new QueryResponse ( ) ;
if ( this . solr0 = = null & & this . solr1 = = null ) return new QueryResponse ( ) ;
if ( this . solr0 ! = null & & this . solr1 = = null ) {
if ( this . solr0 ! = null & & this . solr1 = = null ) {
QueryResponse list = this . solr0 . query ( query ) ;
QueryResponse list = this . solr0 . getResponseByParams ( query ) ;
return list ;
return list ;
}
}
if ( this . solr1 ! = null & & this . solr0 = = null ) {
if ( this . solr1 ! = null & & this . solr0 = = null ) {
QueryResponse list = this . solr1 . query ( query ) ;
QueryResponse list = this . solr1 . getResponseByParams ( query ) ;
return list ;
return list ;
}
}
// combine both lists
// combine both lists
QueryResponse rsp = this . solr0 . query ( query ) ;
QueryResponse rsp = this . solr0 . getResponseByParams ( query ) ;
final SolrDocumentList l = rsp . getResults ( ) ;
final SolrDocumentList l = rsp . getResults ( ) ;
if ( l . size ( ) > = count ) return rsp ;
if ( l . size ( ) > = count ) return rsp ;
@ -253,7 +253,7 @@ public class MirrorSolrConnector extends AbstractSolrConnector implements SolrCo
{ //bad hack - TODO: replace
{ //bad hack - TODO: replace
query . set ( CommonParams . START , 0 ) ;
query . set ( CommonParams . START , 0 ) ;
query . set ( CommonParams . ROWS , Integer . MAX_VALUE ) ;
query . set ( CommonParams . ROWS , Integer . MAX_VALUE ) ;
QueryResponse lHack = this . solr0 . query ( query ) ;
QueryResponse lHack = this . solr0 . getResponseByParams ( query ) ;
query . set ( CommonParams . START , start ) ;
query . set ( CommonParams . START , start ) ;
query . set ( CommonParams . ROWS , count ) ;
query . set ( CommonParams . ROWS , count ) ;
size0 = lHack . getResults ( ) . size ( ) ;
size0 = lHack . getResults ( ) . size ( ) ;
@ -262,7 +262,7 @@ public class MirrorSolrConnector extends AbstractSolrConnector implements SolrCo
// now use the size of the first query to do a second query
// now use the size of the first query to do a second query
query . set ( CommonParams . START , start + l . size ( ) - size0 ) ;
query . set ( CommonParams . START , start + l . size ( ) - size0 ) ;
query . set ( CommonParams . ROWS , count - l . size ( ) ) ;
query . set ( CommonParams . ROWS , count - l . size ( ) ) ;
QueryResponse rsp1 = this . solr1 . query ( query ) ;
QueryResponse rsp1 = this . solr1 . getResponseByParams ( query ) ;
query . set ( CommonParams . START , start ) ;
query . set ( CommonParams . START , start ) ;
query . set ( CommonParams . ROWS , count ) ;
query . set ( CommonParams . ROWS , count ) ;
// TODO: combine both
// TODO: combine both
@ -270,20 +270,20 @@ public class MirrorSolrConnector extends AbstractSolrConnector implements SolrCo
}
}
@Override
@Override
public long get Query Count( final String querystring ) throws IOException {
public long get CountByQuery ( final String querystring ) throws IOException {
if ( this . solr0 = = null & & this . solr1 = = null ) return 0 ;
if ( this . solr0 = = null & & this . solr1 = = null ) return 0 ;
if ( this . solr0 ! = null & & this . solr1 = = null ) {
if ( this . solr0 ! = null & & this . solr1 = = null ) {
return this . solr0 . get Query Count( querystring ) ;
return this . solr0 . get CountByQuery ( querystring ) ;
}
}
if ( this . solr1 ! = null & & this . solr0 = = null ) {
if ( this . solr1 ! = null & & this . solr0 = = null ) {
return this . solr1 . get Query Count( querystring ) ;
return this . solr1 . get CountByQuery ( querystring ) ;
}
}
final AtomicLong count = new AtomicLong ( 0 ) ;
final AtomicLong count = new AtomicLong ( 0 ) ;
Thread t0 = new Thread ( ) {
Thread t0 = new Thread ( ) {
@Override
@Override
public void run ( ) {
public void run ( ) {
try {
try {
count . addAndGet ( MirrorSolrConnector . this . solr0 . get Query Count( querystring ) ) ;
count . addAndGet ( MirrorSolrConnector . this . solr0 . get CountByQuery ( querystring ) ) ;
} catch ( IOException e ) { }
} catch ( IOException e ) { }
}
}
} ;
} ;
@ -292,7 +292,7 @@ public class MirrorSolrConnector extends AbstractSolrConnector implements SolrCo
@Override
@Override
public void run ( ) {
public void run ( ) {
try {
try {
count . addAndGet ( MirrorSolrConnector . this . solr1 . get Query Count( querystring ) ) ;
count . addAndGet ( MirrorSolrConnector . this . solr1 . get CountByQuery ( querystring ) ) ;
} catch ( IOException e ) { }
} catch ( IOException e ) { }
}
}
} ;
} ;