mercredi 1 avril 2015

Redesigning a search engine, what design patterns to apply

I'm really stuck here. I'm trying to do add a new database in addition to a current one. I'm going to use a factory pattern to select the right database control like this:



private AssetStoresFactory assetStoresFactory;

AssetStore assetStore = assetStoreFactory.getAssetStore(query);
assetStore.search(search);

public AssetStore getAssetStore(String query){
AssetStore assetStore;
if (qualifiesForStoreA(query))
assetStore = new AssetStoreA();
else
assetStore = new AssetStoreB();
return assetStore;
}


AssetStore A
.....
Results search(AssetSearch search) {
AssetSearchOperation o = new AssetSearchOperationA(search);
}
.....


AssetStore B
.....
Results search(AssetSearch search) {
AssetSearchOperation o = new AssetSearchOperationB(search);
}
.....


Now the real problem lies here. The current approach to perform searches is like this:



_______________________
| BaseSearchOperation |
| ___________________ |
| abstract search() |
-----------------------

|
____________________
| StreamingSupport |
|__________________|

|
______________________
|AssetSearchOperation|
|____________________|


Now there is code to query the current database in all of the above classes and this needs to be removed and isolated. I can't get my head around how this can be done. Note that anonymous implementations of AssetSearchOperation override StreamingSupport. Any help is appreciated! If you need more information, please do ask!


Aucun commentaire:

Enregistrer un commentaire