我有一个Solr架构,我的对象可以有这两个字段:
例如:
"SerialNumberStart": "0000067098910",
"SerialNumberEnd": "0000067098920",
查询时,我希望能够在查询中传入SerialNumberStart
。如果serialNumber匹配文档的serialNumberStart,我想抓取该文档。但是,当它不匹配时,我想找到我传入的serialNumber所在的所有文件都在SerialNumberStart和SerialNumberEnd之间。我或之后的查询的第二部分应该是: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 *])';
感谢。
答案 0 :(得分:1)
我根据您的说明更新了答案。 您需要调查4个案例: 1 SN存在 2 SN不存在 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不存在,响应将返回“numFound”:1,这是您需要运行搜索的时间。因此,如果没有doc,则查询将如下所示:
回复如下:
{
"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}]
}}
增加行会返回更多文档,修改start可以用作偏移量来获取第N个邻居。
答案 1 :(得分:0)
您的查询似乎与您的内容相反。您正在SerialNumberStart之前和SerialNumberEnd之后找到记录。首先在Solr中获取查询,然后将其映射到Javascript。
此外,您似乎没有引用第一个子句中的值。为了以防万一,您可能希望这样做。