首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >zend search lucene

zend search lucene
EN

Stack Overflow用户
提问于 2009-06-27 15:33:46
回答 1查看 2.6K关注 0票数 4

我有一个数据库,我想通过Zend_Search_Lucene来利用它。然而,我很难为Lucene创建一个“完全可搜索”的文档。

每个Zend_Search_Lucene文档从两个关系数据库表(Table_OneTable_Two)中提取信息。Table_One具有基本信息(idowner_idtitledescriptionlocation等),Table_TwoTable_One具有1:N关系(这意味着,对于Table_One中的每个条目,<代码>d13中可能有一个或多个条目)。Table_Two包含: id、listing_idbedroomsbathroomsprice_minprice_maxdate_available。参见图1。

图1

代码语言:javascript
复制
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

代码语言:javascript
复制
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.

接下来,我需要能够对bedroomsbathroomsprice_minprice_max字段执行范围查询。(例如:查找具有1到3间卧室的文档) Zend_Search_Lucene将仅允许在同一字段上进行范围搜索。据我所知,这意味着我想要进行范围查询的每个字段只能包含一个值(例如:卧室:“1间卧室”);

我现在在Lucene文档中看到的是bedroomsbathroomsprice_minprice_maxdate_available字段都是用空格分隔的。

示例:

代码语言:javascript
复制
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示例文档

代码语言:javascript
复制
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您是否可以对上面所示的bedroombathroomprice_minprice_maxdate_available字段执行范围查询搜索,或者每个范围查询字段必须只包含一个值(例如"1卧室“)?我无法使范围查询以其当前形式工作。我在这里不知所措。

提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-07-01 19:10:42

我建议您为Table_Two中的每个条目创建一个单独的文档。这将导致这些条目共有的Table_One信息的一些重复,但对于Lucene中更简单的索引结构来说,这并不是一个很高的代价。

  1. 使用一个boolean query来合并多个range queries。数值字段应如下所示:

bedrooms: 3

price_min: 900

使用Lucene语法的示例查询将是:

代码语言:javascript
复制
date_available:[20100101 TO 20100301] AND price_min:[600 TO 1000]
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1053039

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档