我有一个数据库,我想通过Zend_Search_Lucene来利用它。然而,我很难为Lucene创建一个“完全可搜索”的文档。
每个Zend_Search_Lucene文档从两个关系数据库表(Table_One和Table_Two)中提取信息。Table_One具有基本信息(id、owner_id、title、description、location等),Table_Two与Table_One具有1:N关系(这意味着,对于Table_One中的每个条目,<代码>d13中可能有一个或多个条目)。Table_Two包含: id、listing_id、bedrooms、bathrooms、price_min、price_max、date_available。参见图1。
图1
Table_One
id (Primary Key)
owner_id
title
description
location
etc...
Table_Two
id (Primary Key)
listing_id (Foreign Key to Table_One)
bedrooms (int)
bathrooms (int)
price_min (int)
price_max (int)
date_available (datetime)问题是,每个Table_One条目都有多个Table_Two条目。问题1如何在每个字段都是唯一的情况下创建Zend_Search_Lucene文档?(参见图2)
图2
Lucene Document
id:Keyword
owner_id:Keyword
title:UnStored
description:UnStored
location: UnStored
date_registered:Keyword
... (other Table_One information)
bedrooms: UnStored
bathrooms: UnStored
price_min: UnStored
price_max: UnStored
date_available: Keyword
bedrooms_1: <- Would prefer not to have do this as this makes the bedrooms harder to search.接下来,我需要能够对bedrooms、bathrooms、price_min和price_max字段执行范围查询。(例如:查找具有1到3间卧室的文档) Zend_Search_Lucene将仅允许在同一字段上进行范围搜索。据我所知,这意味着我想要进行范围查询的每个字段只能包含一个值(例如:卧室:“1间卧室”);
我现在在Lucene文档中看到的是bedrooms,bathrooms,price_min,price_max,date_available字段都是用空格分隔的。
示例:
Sample Table_One Entry:
| 5 | 2 | "Sample Title" | "Sample Description" | "Sample Location" | 2008-01-12
Sample Table_Two Entries:
| 10 | 5 | 3 | 1 | 900 | 1000 | 2009-10-01
| 11 | 5 | 2 | 1 | 800 | 850 | 2009-08-11
| 12 | 5 | 1 | 1 | 650 | 650 | 2009-09-15 Lucene示例文档
id:5
owner_id:2
title: "Sample Title"
description: "Sample Description"
location: "Sample Location"
date_registered: [datetime stamp YYYY-MM-DD]
bedrooms: "3 bedroom 2 bedroom 1 bedroom"
bathrooms: "1 bathroom 1 bathroom 1 bathroom"
price_min: "900 800 650"
price_max: "1000 850 650"
date_available: "2009-10-01 2009-08-11 2009-09-15"问题2您是否可以对上面所示的bedroom、bathroom、price_min、price_max、date_available字段执行范围查询搜索,或者每个范围查询字段必须只包含一个值(例如"1卧室“)?我无法使范围查询以其当前形式工作。我在这里不知所措。
提前谢谢。
发布于 2009-07-01 19:10:42
我建议您为Table_Two中的每个条目创建一个单独的文档。这将导致这些条目共有的Table_One信息的一些重复,但对于Lucene中更简单的索引结构来说,这并不是一个很高的代价。
bedrooms: 3
price_min: 900
使用Lucene语法的示例查询将是:
date_available:[20100101 TO 20100301] AND price_min:[600 TO 1000]https://stackoverflow.com/questions/1053039
复制相似问题