Solr:其中 x 在 y 和 z 之间
Solr: where x is between y and z
我有一个 Solr 模式,我的对象可以在其中包含以下两个字段:
- 序列号开始
- 序列号结束
例如:
"SerialNumberStart": "0000067098910",
"SerialNumberEnd": "0000067098920",
查询时,我希望能够在查询中传入一个SerialNumberStart
。如果该 serialNumber 与文档的 serialNumberStart 匹配,我想获取该文档。但是,当它不匹配时,我想找到我传入的 serialNumber 在 SerialNumberStart 和 SerialNumberEnd 之间的所有文档。在 or 之后我的查询的第二部分应该是这样的:get the documents where someSerialStart is between documentSerialStart and documentSerialEnd
.
我从 JavaScript 建立查询。我试图按如下方式将范围放在一起,但它似乎不正确,但我不知道如何修复它。
var value = req.query['matchedPattern.serialNumber'];
return 'SerialSNumberStart:' + value + ' OR (SerialNumberStart:[* TO ' + value + '] AND SerialNumberEnd:[' + value + ' TO *])';
谢谢。
您的查询好像与您查询的相反。您正在查找 SerialNumberStart 之前和 SerialNumberEnd 之后的记录。首先在 Solr 中获取查询权限,然后将其映射到 Javascript.
另外,您似乎没有引用第一个子句中的值。您可能想这样做以防万一。
我根据您的说明更新了答案。
您需要调查 4 种情况:
1 SN存在
2 序列号不存在
2.1 SN前获取范围
2.2 SN
后获取范围
凭直觉,我肯定会把它分成两块:
存在 1 个 SN,因此将其返回给客户端。这是它的样子:
http://solrserver.us-west-2.compute.amazonaws.com:8983/solr/hellosolr/select?indent=on&q=id:S9V7464-APL-KIT3&wt=json
响应如下:
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"id:S9V7464-APL-KIT3",
"indent":"on",
"wt":"json"}},
"response":{"numFound":1,"start":0,"docs":[
{
"id":"S9V7464-APL-KIT3",
...
如果你的SN不存在,回复returns"numFound":1,这时候你需要运行你的搜索。因此,如果没有文档,查询将如下所示:
响应如下:
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"id:S9V7464-APL-KIT5",
"indent":"on",
"start":"0",
"sort":"id asc",
"rows":"1",
"wt":"json"}},
"response":{"numFound":0,"start":0,"docs":[]
}}
2.1 所以需要SN之前的下一个邻居。我要将两件事添加到降序搜索、排序和答案数量限制中。这是查询想要的内容:
http://solrserver.us-west-2.compute.amazonaws.com:8983/solr/hellosolr/select?indent=on&q=id:[*%20TO%20S9V7464-APL-KIT5]&rows=1&sort=id%20desc&start=0&wt=json
响应如下:
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"id:[* TO S9V7464-APL-KIT5]",
"indent":"on",
"start":"0",
"sort":"id desc",
"rows":"1",
"wt":"json"}},
"response":{"numFound":25,"start":0,"docs":[
{
"id":"S9V7464-APL-KIT3",
"name":["Belkin Mobile Power Cord for iPod w/ Dock"],
"manu":["Belkin"],
"manu_id_s":"belkin",
"cat":["electronics",
"connector"],
"features":["car power adapter, white"],
"weight":[6.7],
"price":[19.95],
"popularity":[1],
"inStock":[false],
"store":["45.18014,-93.87741"],
"manufacturedate_dt":"2005-08-01T16:30:25Z",
"_version_":1547654166135963648}]
}}
2.2 你需要一个升序范围,排序并受返回文档数量的限制。类似于:
http://solrserver.us-west-2.compute.amazonaws.com:8983/solr/hellosolr/select?indent=on&q=id:[S9V7464-APL-KIT5%20TO%20*]&rows=1&sort=id%20asc&start=0&wt=json
响应类似于:
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"id:[S9V7464-APL-KIT5 TO *]",
"indent":"on",
"start":"0",
"sort":"id asc",
"rows":"1",
"wt":"json"}},
"response":{"numFound":8,"start":0,"docs":[
{
"id":"S9V7464-APL-KIT7",
"name":["Belkin Mobile Power Cord for iPod w/ Dock"],
"manu":["Belkin"],
"manu_id_s":"belkin",
"cat":["electronics","connector"],
"features":["car power adapter, white"],
"weight":[6.7],
"price":[19.95],
"popularity":[1],
"inStock":[false],
"store":["45.18014,-93.87741"],
"manufacturedate_dt":"2005-08-01T16:30:25Z",
"_version_":1547654166137012224}]
}}
增加行returns个文档,修改start可以作为偏移得到第N个邻居
我有一个 Solr 模式,我的对象可以在其中包含以下两个字段:
- 序列号开始
- 序列号结束
例如:
"SerialNumberStart": "0000067098910",
"SerialNumberEnd": "0000067098920",
查询时,我希望能够在查询中传入一个SerialNumberStart
。如果该 serialNumber 与文档的 serialNumberStart 匹配,我想获取该文档。但是,当它不匹配时,我想找到我传入的 serialNumber 在 SerialNumberStart 和 SerialNumberEnd 之间的所有文档。在 or 之后我的查询的第二部分应该是这样的:get the documents where someSerialStart is between documentSerialStart and documentSerialEnd
.
我从 JavaScript 建立查询。我试图按如下方式将范围放在一起,但它似乎不正确,但我不知道如何修复它。
var value = req.query['matchedPattern.serialNumber'];
return 'SerialSNumberStart:' + value + ' OR (SerialNumberStart:[* TO ' + value + '] AND SerialNumberEnd:[' + value + ' TO *])';
谢谢。
您的查询好像与您查询的相反。您正在查找 SerialNumberStart 之前和 SerialNumberEnd 之后的记录。首先在 Solr 中获取查询权限,然后将其映射到 Javascript.
另外,您似乎没有引用第一个子句中的值。您可能想这样做以防万一。
我根据您的说明更新了答案。 您需要调查 4 种情况: 1 SN存在 2 序列号不存在 2.1 SN前获取范围 2.2 SN
后获取范围凭直觉,我肯定会把它分成两块: 存在 1 个 SN,因此将其返回给客户端。这是它的样子:
http://solrserver.us-west-2.compute.amazonaws.com:8983/solr/hellosolr/select?indent=on&q=id:S9V7464-APL-KIT3&wt=json
响应如下:
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"id:S9V7464-APL-KIT3",
"indent":"on",
"wt":"json"}},
"response":{"numFound":1,"start":0,"docs":[
{
"id":"S9V7464-APL-KIT3",
...
如果你的SN不存在,回复returns"numFound":1,这时候你需要运行你的搜索。因此,如果没有文档,查询将如下所示:
响应如下:
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"id:S9V7464-APL-KIT5",
"indent":"on",
"start":"0",
"sort":"id asc",
"rows":"1",
"wt":"json"}},
"response":{"numFound":0,"start":0,"docs":[]
}}
2.1 所以需要SN之前的下一个邻居。我要将两件事添加到降序搜索、排序和答案数量限制中。这是查询想要的内容:
http://solrserver.us-west-2.compute.amazonaws.com:8983/solr/hellosolr/select?indent=on&q=id:[*%20TO%20S9V7464-APL-KIT5]&rows=1&sort=id%20desc&start=0&wt=json
响应如下:
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"id:[* TO S9V7464-APL-KIT5]",
"indent":"on",
"start":"0",
"sort":"id desc",
"rows":"1",
"wt":"json"}},
"response":{"numFound":25,"start":0,"docs":[
{
"id":"S9V7464-APL-KIT3",
"name":["Belkin Mobile Power Cord for iPod w/ Dock"],
"manu":["Belkin"],
"manu_id_s":"belkin",
"cat":["electronics",
"connector"],
"features":["car power adapter, white"],
"weight":[6.7],
"price":[19.95],
"popularity":[1],
"inStock":[false],
"store":["45.18014,-93.87741"],
"manufacturedate_dt":"2005-08-01T16:30:25Z",
"_version_":1547654166135963648}]
}}
2.2 你需要一个升序范围,排序并受返回文档数量的限制。类似于:
http://solrserver.us-west-2.compute.amazonaws.com:8983/solr/hellosolr/select?indent=on&q=id:[S9V7464-APL-KIT5%20TO%20*]&rows=1&sort=id%20asc&start=0&wt=json
响应类似于:
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"id:[S9V7464-APL-KIT5 TO *]",
"indent":"on",
"start":"0",
"sort":"id asc",
"rows":"1",
"wt":"json"}},
"response":{"numFound":8,"start":0,"docs":[
{
"id":"S9V7464-APL-KIT7",
"name":["Belkin Mobile Power Cord for iPod w/ Dock"],
"manu":["Belkin"],
"manu_id_s":"belkin",
"cat":["electronics","connector"],
"features":["car power adapter, white"],
"weight":[6.7],
"price":[19.95],
"popularity":[1],
"inStock":[false],
"store":["45.18014,-93.87741"],
"manufacturedate_dt":"2005-08-01T16:30:25Z",
"_version_":1547654166137012224}]
}}
增加行returns个文档,修改start可以作为偏移得到第N个邻居