solr - Solr 索引相关表
问题描述
我有一个 solr 实例,其中 DataImportHandler 指向我的数据库,其中有一些表映射到 json 之类的......
[
{
"id": 1,
"name": "Soap",
"price": "2.00",
"description": "It cleans things"
"category_list: [
{
"id":1,
"location": "store",
"name": "cleaner"
}, {
"id": 2,
"location": "online",
"name": "home"
}
]
}
基本上有分类的产品。
我将索引器指向了这个,但是当我对产品进行查询时,我最终得到的结果是“类别”被分成单独的列表
{
name: ["cleaner", "home"]
location: ["store", "online"]
id: [1, 2]
}
它颠倒了关系并失去了上下文。如果我想问它的类别位置是“商店”并且名称是“家”,它会找到在商店中有任何库存的任何东西和任何类别是“家”的东西。它没有将其放在同一个子对象中的上下文。
有没有办法告诉 solr 正确索引、存储和检索这些?我可以给它提供表格或json或其他任何东西,但我希望它恢复原始形状,并且我想以原始形状查询它。
所以data-config.xml是这样的
<dataConfig>
<dataSource type="JdbcDataSource" driver="org.postgresql.Driver" url="jdbc:postgresql://pghostname:5432/db" user="user" password="pass" />
<document >
<entity name="products"
pk="id"
query="SELECT * from products">
<field column="id" name="id"/>
<field column="name" name="name"/>
<field column="price" name="price"/>
<field column="description" name="description"/>
<entity name="product_categories"
pk="category_id"
query="SELECT * from product_categories where product_id = ${product.id}">
<field column="category_id" name="category_id"/>
<field column="location" name="location"/>
<field column="name" name="name"/>
</entity>
</entity>
</document>
</dataConfig>
这是 postgres 数据库的一些示例数据
create table products (
id integer generated by default as identity,
name varchar,
price varchar,
description varchar,
primary key(id)
);
create table product_categories (
category_id integer generated by default as identity,
name varchar,
location varchar,
product_id integer,
foreign key (product_id) references products(id),
primary key(category_id)
);
insert into products
(name, price, description)
values
('Soap', '2.13', 'this is soap'),
('Pencils', '0.89', 'pencils write things'),
('Scissors', '5.00', 'scissors sciss');
insert into product_categories
(name, location, product_id)
values
('home', 'in-store', 1),
('office', 'online', 2),
('office', 'in-store', 3),
('home', 'in-store', 2);
你可以看到有一个单一的关系。但是在导入这个并进行查询之后,我们会看到类似...的结果
"response":{"numFound":3,"start":0,"docs":[
{
"price":"2.13",
"name":"Soap",
"description":"this is soap",
"id":"1",
"category_id":"1",
"location":"in-store",
"_version_":1658459282145804288},
...
这清楚地把两张桌子平成了一个物体
解决方案
推荐阅读
- javascript - 延迟将显示更改为无
- batch-file - 如何从批处理中仅签入 TFS 中的特定分支?
- java - 我收到应用程序构建错误,资源“attr/arc_position”的重复值与配置“”
- android - 如何使用 androguard 或 aapt 从 .apk 中提取过滤器意图?
- javascript - JavaScript 'myFunction' 不是一个函数,尽管它是
- flutter - 如何在不同类的迭代器 FOR 中传递变量列表?
- machine-learning - Word2Vec 本身是判别模型还是生成模型?
- apache-spark - Spark sql“创建表作为选择...”内存不足
- python - 编码熊猫数据框
- c++ - 这个问题怎么解决,回溯?向量?