Skip to content

Commit

Permalink
Remove LTR component (apache#75)
Browse files Browse the repository at this point in the history
* remove ltr-component

* update README

* fix example

* update example files

* reuse MenagedModelStore

* replace type with class in LibSvmFormatter

* debugging

* change cloud test first query to return docs 1..4

* refactor cloud tests

* randomizing shards and replicas

* randomize number of shards and replicas in cloud test
  • Loading branch information
diegoceccarelli authored and Michael Nilsson committed Sep 28, 2016
1 parent 70c1682 commit 1542683
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 167 deletions.
17 changes: 1 addition & 16 deletions solr/contrib/ltr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,8 @@ BONUS: Train an actual machine learning model
transformer enclosed between brackets (in this case [features]).
In order to get the feature vector you will have to
specify that you want the field (e.g., fl="*,[features]) -->
<transformer name="features" class="org.apache.solr.ltr.ranking.LTRFeatureLoggerTransformerFactory" />


<!-- Component that hooks up managed resources for features and models -->
<searchComponent name="ltrComponent" class="org.apache.solr.ltr.ranking.LTRComponent"/>
<requestHandler name="/query" class="solr.SearchHandler">
<lst name="defaults">
<str name="echoParams">explicit</str>
<str name="wt">json</str>
<str name="indent">true</str>
<str name="df">id</str>
</lst>
<arr name="last-components">
<!-- Use the component in your requestHandler -->
<str>ltrComponent</str>
</arr>
</requestHandler>
<transformer name="features" class="org.apache.solr.ltr.ranking.LTRFeatureLoggerTransformerFactory" />

<query>
...
Expand Down
8 changes: 1 addition & 7 deletions solr/contrib/ltr/example/solrconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,6 @@
<transformer name="features" class="org.apache.solr.ltr.ranking.LTRFeatureLoggerTransformerFactory" />


<!-- Component that hooks up managed resources for features and models -->
<searchComponent name="ltrComponent" class="org.apache.solr.ltr.ranking.LTRComponent" />
<!-- A request handler that returns indented JSON by default -->
<requestHandler name="/query" class="solr.SearchHandler">
<lst name="defaults">
Expand All @@ -879,11 +877,7 @@
<str name="indent">true</str>
<str name="df">text</str>
</lst>
<arr name="last-components">
<!-- Use the component in your requestHandler -->
<str>ltrComponent</str>
</arr>
</requestHandler>
</requestHandler>


<!-- A Robust Example
Expand Down
8 changes: 4 additions & 4 deletions solr/contrib/ltr/example/techproducts-features.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
[
{
"name": "isInStock",
"type": "org.apache.solr.ltr.feature.impl.FieldValueFeature",
"class": "org.apache.solr.ltr.feature.impl.FieldValueFeature",
"params": {
"field": "inStock"
}
},
{
"name": "price",
"type": "org.apache.solr.ltr.feature.impl.FieldValueFeature",
"class": "org.apache.solr.ltr.feature.impl.FieldValueFeature",
"params": {
"field": "price"
}
},
{
"name":"originalScore",
"type":"org.apache.solr.ltr.feature.impl.OriginalScoreFeature",
"class":"org.apache.solr.ltr.feature.impl.OriginalScoreFeature",
"params":{}
},
{
"name" : "productNameMatchQuery",
"type" : "org.apache.solr.ltr.feature.impl.SolrFeature",
"class" : "org.apache.solr.ltr.feature.impl.SolrFeature",
"params" : { "q" : "{!field f=name}${user_query}" }
}
]
2 changes: 1 addition & 1 deletion solr/contrib/ltr/example/techproducts-model.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type":"org.apache.solr.ltr.ranking.RankSVMModel",
"class":"org.apache.solr.ltr.ranking.RankSVMModel",
"name":"svm",
"features":[
{"name":"isInStock"},
Expand Down
2 changes: 1 addition & 1 deletion solr/contrib/ltr/scripts/libSvmFormatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _getFeatureId(self,key):
def convertLibSvmModelToLtrModel(self,libSvmModelLocation, outputFile, modelName):
with open(libSvmModelLocation, 'r') as inFile:
with open(outputFile,'w') as convertedOutFile:
convertedOutFile.write('{\n\t"type":"org.apache.solr.ltr.ranking.RankSVMModel",\n')
convertedOutFile.write('{\n\t"class":"org.apache.solr.ltr.ranking.RankSVMModel",\n')
convertedOutFile.write('\t"name": "' + str(modelName) + '",\n')
convertedOutFile.write('\t"features": [\n')
isFirst = True;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,27 @@
*/
package org.apache.solr.ltr.ranking;

import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.Map;

import org.apache.lucene.analysis.util.ResourceLoader;
import org.apache.lucene.analysis.util.ResourceLoaderAware;
import org.apache.lucene.search.Query;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.ltr.log.FeatureLogger;
import org.apache.solr.ltr.model.LTRScoringModel;
import org.apache.solr.core.SolrResourceLoader;
import org.apache.solr.ltr.rest.ManagedFeatureStore;
import org.apache.solr.ltr.rest.ManagedModelStore;
import org.apache.solr.ltr.util.CommonLTRParams;
import org.apache.solr.ltr.util.LTRUtils;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.rest.ManagedResource;
import org.apache.solr.rest.ManagedResourceObserver;
import org.apache.solr.search.QParser;
import org.apache.solr.search.QParserPlugin;
import org.apache.solr.search.SyntaxError;
Expand All @@ -44,10 +51,13 @@
* efi.myCompanyQueryIntent=0.98}
*
*/
public class LTRQParserPlugin extends QParserPlugin {
public class LTRQParserPlugin extends QParserPlugin implements ResourceLoaderAware, ManagedResourceObserver {
public static final String NAME = "ltr";

private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

private ManagedFeatureStore fr = null;
private ManagedModelStore mr = null;

@Override
public void init(@SuppressWarnings("rawtypes") NamedList args) {
Expand All @@ -63,9 +73,34 @@ public QParser createParser(String qstr, SolrParams localParams,
return new LTRQParser(qstr, localParams, params, req);
}

public class LTRQParser extends QParser {
@Override
public void inform(ResourceLoader loader) throws IOException {
SolrResourceLoader solrResourceLoader = (SolrResourceLoader) loader;
solrResourceLoader.getManagedResourceRegistry().
registerManagedResource(CommonLTRParams.FEATURE_STORE_END_POINT, ManagedFeatureStore.class, this);

ManagedModelStore mr = null;
solrResourceLoader.getManagedResourceRegistry().
registerManagedResource(CommonLTRParams.MODEL_STORE_END_POINT, ManagedModelStore.class, this);

}

@Override
public void onManagedResourceInitialized(NamedList<?> args, ManagedResource res) throws SolrException {
if (res instanceof ManagedFeatureStore) {
fr = (ManagedFeatureStore)res;
}
if (res instanceof ManagedModelStore){
mr = (ManagedModelStore)res;
}
if (mr != null && fr != null){
mr.init(fr);
// now we can safely load the models
mr.loadStoredModels();

}
}

public class LTRQParser extends QParser {

public LTRQParser(String qstr, SolrParams localParams, SolrParams params,
SolrQueryRequest req) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
initialSize="2048" autowarmCount="4096" regenerator="solr.search.NoOpRegenerator" />
</query>


<searchComponent name="ltrComponent"
class="org.apache.solr.ltr.ranking.LTRComponent" />

<!-- add a transformer that will encode the document features in the response.
For each document the transformer will add the features as an extra field
in the response. The name of the field we will be the the name of the transformer
Expand Down Expand Up @@ -64,9 +60,6 @@
<str name="indent">true</str>
<str name="df">id</str>
</lst>
<arr name="last-components">
<str>ltrComponent</str>
</arr>
</requestHandler>

</config>
Loading

0 comments on commit 1542683

Please sign in to comment.