简体   繁体   English

是否可以在Solr中创建一个多值多字段,以允许在查询时使用自定义逻辑?

[英]Is it possible to create a multivalued polyfield in Solr that will allow custom logic at query time?

I'm working with a pretty niche requirement to model a relational structure within Solr and thought that a custom polyfield would be the most suitable solution to my problem. 我正在处理一个相当合适的需求,以便在Solr中为关系结构建模,并认为自定义多边形将是最适合我的问题的解决方案。 In short, each record in the index will have a number of embargo and expiry dates for when the content should be considered 'available'. 简而言之,索引中的每条记录都会有许多禁令和有效期,以决定何时将内容视为“可用”。 These dates are grouped with another kind of categorisation (let's say by device), so for example, any given item in the index may be available for mobile users between two dates, but only available for desktop users between another two dates. 这些日期通过另一种分类(按设备分类)进行分组,因此,例如,索引中的任何给定项目可能在两个日期之间对移动用户可用,但仅在另外两个日期之间对桌面用户可用。

Much like the currency and the latlon types, I would index the values as a comma separated list representing each availability window, for example: 就像货币和latlon类型一样,我会将值索引为一个逗号分隔的列表,代表每个可用性窗口,例如:

mobile,2013-09-23T00:00:00Z,2013-09-30T00:00:00Z 

So, a single index record could look like 因此,单个索引记录可能看起来像

{
    id: "1234",
    text: ["foobarbaz"],
    availability: [
        "mobile,2013-09-23T00:00:00Z,2013-09-30T00:00:00Z",
        "pc,2013-09-22T00:00:00Z,2013-09-30T00:00:00Z"
    ]
}

The custom type would do the job of parsing the incoming value and storing it accordingly. 自定义类型将完成解析传入的值并进行相应存储的工作。 Is this a viable solution? 这是可行的解决方案吗? How would I approach the custom logic required at query time to filter by device and then make sure that NOW is within the provided dates? 如何处理查询时所需的自定义逻辑以按设备进行过滤,然后确保NOW在提供的日期之内?

My attempt so far has been based on the Currency field type, but now I've dialled it back to just storing the string in its un-parsed state. 到目前为止,我的尝试一直基于Currency字段类型,但现在我已将其回拨到只是将字符串存储为未解析状态。 If I could prove that the filtering I want is even possible before using the polyfield features, then I'll know if it's worth continuing. 如果可以证明在使用多字段功能之前甚至可以进行所需的过滤,那么我将继续进行下去。

Does anybody else have any experience writing custom (poly)fields, or doing anything similar to what I'm doing? 其他人是否有编写自定义(多边形)字段或进行与我正在执行的操作类似的经验?

Thanks! 谢谢!

If you want to be able to filter and search on these ranges, I don't think you'll have much luck storing records like that. 如果您希望能够在这些范围内进行过滤和搜索,那么我认为存储这样的记录不会很幸运。 It would make more sense to me to have a more structured document, something like: 对于我来说,拥有一个结构更合理的文档会更有意义,例如:

id: "1234",
text: ["foobarbaz"],
mobileavailabilitystart: "mobile,2013-09-23T00:00:00Z",
mobileavailabilityend: "2013-09-30T00:00:00Z",
pcavailabilitystart: "2013-09-22T00:00:00Z", 
pcavailabilityend: "2013-09-30T00:00:00Z"

Indexing the full contents of a csv line in Lucene/Solr, in a single field, would allow you to perform full-text searches on it, but would not be a good way to support querying for a specific element of it. 在单个字段中为Lucene / Solr中的csv行的全部内容建立索引,将使您能够对其进行全文搜索,但不是支持查询特定元素的好方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM