zend search lucene

4
我有一个数据库想要与Zend_Search_Lucene一起使用。但是,我在为Lucene创建“完全可搜索”的文档方面遇到了困难。
每个Zend_Search_Lucene文档都从两个关系型数据库表(Table_OneTable_Two)中提取信息。Table_One具有基本信息(idowner_idtitledescriptionlocation等),Table_TwoTable_One存在1:N的关系(这意味着对于Table_One中的每个条目,Table_Two中可能有一个或多个条目)。Table_Two包含:id、listing_idbedroomsbathroomsprice_minprice_maxdate_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_One条目都有多个Table_Two条目。[问题1]如何创建一个Zend_Search_Lucene文档,使得每个字段都是唯一的?(见图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.

接下来,我需要能够对“卧室”、“浴室”、“最低价格”和“最高价格”这些字段进行范围查询。(例如:查找拥有1到3个卧室的文档)但是,Zend_Search_Lucene 只允许在同一字段上进行范围搜索。据我所知,这意味着我想要进行范围查询的每个字段只能包含一个值(例如:bedrooms:“1 bedroom”)。
目前,在 Lucene 文档中,我有“卧室”、“浴室”、“最低价格”、“最高价格”和“可用日期”这些字段,它们之间用空格分隔。
示例:
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] 你能在上述展示的卧室浴室最低价格最高价格可用日期字段上执行范围查询搜索吗?还是每个范围查询字段只能包含一个值(例如“1间卧室”)?我无法使范围查询在其当前形式下正常工作。我在这里有些迷茫。

提前致谢。

1个回答

2
我建议您为Table_Two中的每个条目创建一个单独的Lucene文档。这将导致一些Table_One信息在这些条目中重复,但这不是为了更容易的Lucene索引结构而付出的高昂代价。
使用boolean query来组合多个range queries。 数值字段应该像这样:

卧室数:3

最低价格:900

Lucene语法中的示例查询将是:
date_available:[20100101 TO 20100301] AND price_min:[600 TO 1000]

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接