<jupyter_start><jupyter_text>Reset LTR storesThe request below will clear any models under the test store.<jupyter_code>url = "http://{}:8983/solr/tmdb/schema/model-store/test".format(host)
print(url)
requests.delete(url)<jupyter_output><empty_output><jupyter_text>This request will clear the test feature-store<jupyter_code>url = "http://{}:8983/solr/tmdb/schema/feature-store/test".format(host)
print(url)
requests.delete(url)<jupyter_output><empty_output><jupyter_text>To upload a new feature-store named `test`:<jupyter_code>feature_set = [
    {
      "name" : "title_bm25",
      "store": "test",
      "class" : "org.apache.solr.ltr.feature.SolrFeature",
      "params" : { #q=title:({$keywords})
        "q" : "title:(${keywords})"
      }
    },
    {
      "name" : "overview_bm25",
      "store": "test",
      "class" : "org.apache.solr.ltr.feature.SolrFeature",
      "params" : {
        "q" : "overview:(${keywords})"
      }
    },
    {
      "name" : "vote_average",
      "store": "test",
      "class" : "org.apache.solr.ltr.feature.SolrFeature",
      "params" : {
        "q" : "{!func}vote_average"
      }
    }
   
]

url = 'http://{}:8983/solr/tmdb/schema/feature-store'.format(host)
print(url)
requests.put(url, json=feature_set)<jupyter_output><empty_output><jupyter_text>To verify the new feature-store, issue the following GET request:<jupyter_code>url = 'http://{}:8983/solr/tmdb/schema/feature-store/test'.format(host)
print(url)
resp = requests.get(url)
resp.json()<jupyter_output><empty_output><jupyter_text>Searching and LoggingThe following request will query and log features from the test feature-store.<jupyter_code># grade    docId       query
# 4        7555        rambo
# ...
# 0        1368        rambo
# 4        12414       rocky

params = {
    "fl": "id,title,[features store=test efi.keywords=\"rambo\"]",
    'q': "id:7555 OR id:1370 id:1369 OR id:1368", #rambo's graded documents
    'rows': 10,
    'wt': 'json'  
}

url = 'http://{}:8983/solr/tmdb/select'.format(host)
print(url)
resp = requests.post(url, data=params).json()
resp<jupyter_output><empty_output><jupyter_text>```4    qid:1   1:12.31     2:10.56    3:6.44    qid:1   1:12.357876     2:11.95039    3:0.04    qid:1   1:7.010513     2:11.95039    3:0.03    qid:1   .........4    qid:2```  Uploading a ModelOnce features have been logged and training data has been generated, a model can be pushed into Solr. The following code shows how to upload a pre-trained model.<jupyter_code>model = """## LambdaMART
## No. of trees = 10
## No. of leaves = 10
## No. of threshold candidates = 256
## Learning rate = 0.1
## Stop early = 100

<ensemble>
	<tree id="1" weight="0.1">
		<split>
			<feature> 2 </feature>
			<threshold> 10.664251 </threshold>
			<split pos="left">
				<feature> 1 </feature>
				<threshold> 0.0 </threshold>
				<split pos="left">
					<output> -1.8305741548538208 </output>
				</split>
				<split pos="right">
					<feature> 2 </feature>
					<threshold> 9.502127 </threshold>
					<split pos="left">
						<feature> 1 </feature>
						<threshold> 7.0849166 </threshold>
						<split pos="left">
							<output> 0.23645669221878052 </output>
						</split>
						<split pos="right">
							<output> 1.7593677043914795 </output>
						</split>
					</split>
					<split pos="right">
						<output> 1.9719607830047607 </output>
					</split>
				</split>
			</split>
			<split pos="right">
				<feature> 2 </feature>
				<threshold> 0.0 </threshold>
				<split pos="left">
					<output> 1.3728954792022705 </output>
				</split>
				<split pos="right">
					<feature> 2 </feature>
					<threshold> 8.602512 </threshold>
					<split pos="left">
						<feature> 1 </feature>
						<threshold> 0.0 </threshold>
						<split pos="left">
							<feature> 2 </feature>
							<threshold> 13.815164 </threshold>
							<split pos="left">
								<output> 1.9401178359985352 </output>
							</split>
							<split pos="right">
								<output> 1.99532949924469 </output>
							</split>
						</split>
						<split pos="right">
							<feature> 1 </feature>
							<threshold> 11.085816 </threshold>
							<split pos="left">
								<output> 2.0 </output>
							</split>
							<split pos="right">
								<output> 1.99308180809021 </output>
							</split>
						</split>
					</split>
					<split pos="right">
						<output> 1.9870178699493408 </output>
					</split>
				</split>
			</split>
		</split>
	</tree>
</ensemble>
"""

from ltr.helpers.convert import convert

feature_mapping = [{'name': 'title_bm25'}, {'name': 'overview_bm25'}]

solr_model = convert(model, 'test', 'test', feature_mapping)
print(json.dumps(solr_model, indent=2))
url = 'http://{}:8983/solr/tmdb/schema/model-store'.format(host)
print(url)
requests.put(url, json=solr_model)<jupyter_output><empty_output><jupyter_text>Searching with a ModelNow that a model is uploaded, we can use it to re-rank the results in Solr.<jupyter_code>params = {
    'q': '{!ltr model=test efi.keywords=\"rambo\"}',
    'rows': 10,
    'wt': 'json',
    'fl': 'title'
}

url = 'http://{}:8983/solr/tmdb/select'.format(host)
print(url)
resp = requests.post(url, data=params).json()
resp<jupyter_output><empty_output><jupyter_text>Rerank QueryThe follwing example shows how to use a rerank query<jupyter_code>params = {
    'q': 'rambo',
    'rows': 10,
    'wt': 'json',
    'fl': 'title',
    'rq': '{!ltr reRankDocs=50 model=test efi.keywords=\"rambo\"}'
}

url = 'http://{}:8983/solr/tmdb/select'.format(host)
print(url)
resp = requests.post(url, data=params).json()
resp<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup