@ -231,8 +231,8 @@ public class MirrorSolrConnector extends AbstractSolrConnector implements SolrCo
}
@Override
public SolrDocument get ( String id ) throws IOException {
SolrDocument doc = this . documentCache . get ( id ) ;
public SolrDocument get ( final String id , final String . . . fields ) throws IOException {
SolrDocument doc = fields . length = = 0 ? this . documentCache . get ( id ) : null ;
if ( doc ! = null ) {
this . documentCache_Hit + + ;
return doc ;
@ -243,24 +243,22 @@ public class MirrorSolrConnector extends AbstractSolrConnector implements SolrCo
return null ;
}
missCache_Miss + + ;
if ( ( solr0 ! = null & & ( ( doc = solr0 . get ( id )) ! = null ) ) | | ( solr1 ! = null & & ( ( doc = solr1 . get ( id ) ) ! = null ) ) ) {
if ( ( solr0 ! = null & & ( ( doc = solr0 . get ( id , fields )) ! = null ) ) | | ( solr1 ! = null & & ( ( doc = solr1 . get ( id , fields ) ) ! = null ) ) ) {
this . missCache . remove ( id ) ;
this . hitCache . put ( id , EXIST ) ;
this . hitCache_Insert + + ;
this . documentCache . put ( id , doc ) ;
this . documentCache_Insert + + ;
if ( fields . length = = 0 ) { this . documentCache . put ( id , doc ) ; this . documentCache_Insert + + ; }
return doc ;
}
// check if there is a autocommit problem
if ( this . hitCache . containsKey ( id ) ) {
// the document should be there, therefore make a commit and check again
this . commit ( ) ;
if ( ( solr0 ! = null & & ( ( doc = solr0 . get ( id )) ! = null ) ) | | ( solr1 ! = null & & ( ( doc = solr1 . get ( id ) ) ! = null ) ) ) {
if ( ( solr0 ! = null & & ( ( doc = solr0 . get ( id , fields )) ! = null ) ) | | ( solr1 ! = null & & ( ( doc = solr1 . get ( id , fields ) ) ! = null ) ) ) {
this . missCache . remove ( id ) ;
this . hitCache . put ( id , EXIST ) ;
this . hitCache_Insert + + ;
this . documentCache . put ( id , doc ) ;
this . documentCache_Insert + + ;
if ( fields . length = = 0 ) { this . documentCache . put ( id , doc ) ; this . documentCache_Insert + + ; }
return doc ;
}
}
@ -276,7 +274,7 @@ public class MirrorSolrConnector extends AbstractSolrConnector implements SolrCo
* /
@Override
public void add ( final SolrInputDocument solrdoc ) throws IOException {
String id = ( String ) solrdoc . getFieldValue ( YaCySchema . id . n ame( ) ) ;
String id = ( String ) solrdoc . getFieldValue ( YaCySchema . id . getSolrFieldN ame( ) ) ;
assert id ! = null ;
if ( id = = null ) return ;
this . missCache . remove ( id ) ;
@ -300,47 +298,47 @@ public class MirrorSolrConnector extends AbstractSolrConnector implements SolrCo
* @throws IOException
* /
@Override
public SolrDocumentList query ( final String querystring , final int offset , final int count ) throws IOException {
public SolrDocumentList query ( 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 ( offset = = 0 & & count = = 1 & & querystring . startsWith ( "id:" ) ) {
final SolrDocumentList list = new SolrDocumentList ( ) ;
SolrDocument doc = get ( querystring . charAt ( 3 ) = = '"' ? querystring . substring ( 4 , querystring . length ( ) - 1 ) : querystring . substring ( 3 ) );
SolrDocument doc = get ( querystring . charAt ( 3 ) = = '"' ? querystring . substring ( 4 , querystring . length ( ) - 1 ) : querystring . substring ( 3 ) , fields );
list . add ( doc ) ;
// no addToCache(list) here because that was already handlet in get();
return list ;
}
if ( this . solr0 ! = null & & this . solr1 = = null ) {
SolrDocumentList list = this . solr0 . query ( querystring , offset , count );
addToCache ( list ) ;
SolrDocumentList list = this . solr0 . query ( querystring , offset , count , fields );
if ( fields . length = = 0 ) addToCache ( list ) ;
return list ;
}
if ( this . solr1 ! = null & & this . solr0 = = null ) {
SolrDocumentList list = this . solr1 . query ( querystring , offset , count );
addToCache ( list ) ;
SolrDocumentList list = this . solr1 . query ( querystring , offset , count , fields );
if ( fields . length = = 0 ) addToCache ( list ) ;
return list ;
}
// combine both lists
SolrDocumentList l ;
l = this . solr0 . query ( querystring , offset , count );
l = this . solr0 . query ( querystring , offset , count , fields );
if ( l . size ( ) > = count ) return l ;
// 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
int size0 = 0 ;
{ //bad hack - TODO: replace
SolrDocumentList lHack = this . solr0 . query ( querystring , 0 , Integer . MAX_VALUE );
SolrDocumentList lHack = this . solr0 . query ( querystring , 0 , Integer . MAX_VALUE , fields );
size0 = lHack . size ( ) ;
}
// now use the size of the first query to do a second query
final SolrDocumentList list = new SolrDocumentList ( ) ;
for ( final SolrDocument d : l ) list . add ( d ) ;
l = this . solr1 . query ( querystring , offset + l . size ( ) - size0 , count - l . size ( ) );
l = this . solr1 . query ( querystring , offset + l . size ( ) - size0 , count - l . size ( ) , fields );
for ( final SolrDocument d : l ) list . add ( d ) ;
// add caching
addToCache ( list ) ;
if ( fields . length = = 0 ) addToCache ( list ) ;
return list ;
}
@ -422,16 +420,16 @@ public class MirrorSolrConnector extends AbstractSolrConnector implements SolrCo
}
@Override
public Map < String , ReversibleScoreMap < String > > getFacets ( String query , String [ ] fields , int maxresult s) throws IOException {
public Map < String , ReversibleScoreMap < String > > getFacets ( final String query , final int maxresults , final String . . . field s) throws IOException {
if ( this . solr0 = = null & & this . solr1 = = null ) return new HashMap < String , ReversibleScoreMap < String > > ( 0 ) ;
if ( this . solr0 ! = null & & this . solr1 = = null ) {
return this . solr0 . getFacets ( query , fields, maxresult s) ;
return this . solr0 . getFacets ( query , maxresults, field s) ;
}
if ( this . solr1 ! = null & & this . solr0 = = null ) {
return this . solr1 . getFacets ( query , fields, maxresult s) ;
return this . solr1 . getFacets ( query , maxresults, field s) ;
}
Map < String , ReversibleScoreMap < String > > facets0 = this . solr0 . getFacets ( query , fields, maxresult s) ;
Map < String , ReversibleScoreMap < String > > facets1 = this . solr1 . getFacets ( query , fields, maxresult s) ;
Map < String , ReversibleScoreMap < String > > facets0 = this . solr0 . getFacets ( query , maxresults, field s) ;
Map < String , ReversibleScoreMap < String > > facets1 = this . solr1 . getFacets ( query , maxresults, field s) ;
for ( Map . Entry < String , ReversibleScoreMap < String > > facet0 : facets0 . entrySet ( ) ) {
ReversibleScoreMap < String > facet1 = facets1 . remove ( facet0 . getKey ( ) ) ;
if ( facet1 = = null ) continue ;