【问题标题】:Use Lucene index with Document将 Lucene 索引与 Document 一起使用
【发布时间】:2016-02-24 09:49:31
【问题描述】:

我需要存储结构化文档,并且我需要能够通过搜索属性找到它们。

例如:

CREATE CLASS testDocument
INSERT INTO testDocument (my_prop) values ({"name": "James", "age": 23})
INSERT INTO testDocument (my_prop) values ({"name": "John", "age": 51, "tatoos": ["dragon", "jellyfish", "baloon"]})

从那里我可以直接检索数据,例如:

SELECT my_prop.tatoos[0] FROM testDocument WHERE my_prop.age=51

但我无法搜索到整个对象。有没有办法在文档中的任何地方找到“龙”这个词? 我尝试添加 LUCENE 索引但没有成功。如果需要定义这种属性(结构化文档)的类型是什么?

谢谢 洛朗

【问题讨论】:

  • 您使用的是什么版本的 OrientDb?

标签: lucene orientdb


【解决方案1】:

你可以用这个

SELECT my_prop.name FROM testDocument WHERE my_prop.tatoos contains "dragon"

【讨论】:

  • 谢谢,但这样我必须知道搜索字符串在结构中的精确存储位置,而我不知道。我需要的是 SELECT FROM testDocument where my_prop contains "dragon" 之类的东西,因为底层结构没有预定义。
【解决方案2】:

如果需要定义此类属性的类型,可以使用embeddedlist for tatoos

CREATE CLASS testDocument

create property testDocument.name String 
create property testDocument.age Integer
create property testDocument.tatoos Embeddedlist String

INSERT INTO testDocument content {"name": "James", "age": 23}
INSERT INTO testDocument content {"name": "John", "age": 51, "tatoos": ["dragon", "jellyfish", "baloon"]}

你可以使用这个查询

SELECT FROM testDocument where age=51 and tatoos contains "dragon"

更新

你可以使用这个查询

select from testDocument where my_prop.toJSON('fetchPlan:*:-1').indexOf("dragon") > -1

【讨论】:

  • 谢谢,但是没有预定义结构,每个对象都可以有自己的。这就是我需要无模式数据的原因。所以我不能将它们存储在这样的属性中。
猜你喜欢
  • 1970-01-01
  • 2012-04-26
  • 2011-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-03
  • 2023-03-19
相关资源
最近更新 更多