我有一个我想利用的数据库Zend_Search_Lucene
。但是,我很难为 Lucene 创建一个“完全可搜索”的文档。
每个文档从两个关系数据库表(和)中Zend_Search_Lucene
提取信息。具有基本信息(、、、、等),与(意味着,对于 中的每个条目,在 中可能有一个或多个条目)具有 1:N 关系。Table_Two 包含:id, , , , , , . 请参见图 1。Table_One
Table_Two
Table_One
id
owner_id
title
description
location
Table_Two
Table_One
Table_One
Table_Two
listing_id
bedrooms
bathrooms
price_min
price_max
date_available
图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_Two
问题是,每个条目都有多个条目Table_One
。[问题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间卧室”)?我无法让 Range Query 以其当前形式工作。我在这里不知所措。
提前致谢。