我想在cakephp中集成solr搜索,一切都可以正常查询但是当我在我的mysql查询中添加GROUP_CONCATE然后我无法索引我的solr搜索 我的代码列在下面
<dataSource name="db2" type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/website"
user="webname"
password="123456"/>
<document name="content">
<entity name="web"
transformer="RegexTransformer"
query="SELECT (SELECT GROUP_CONCAT(name separator ',') FROM tags JOIN article_tags ON tags.id = article_tags.tag_id WHERE article_tags.article_id = article.id) as tagnames,
Article.id, Article.title, Article.sub_title, Article.category_id,
Article.section_title, Article.section_body, Category.id as cat_id,
Category.name as cat_name, Recipe.id as recipe_id, Recipe.recipe_title, ArticleMultiBody.id as multi_id,
ArticleMultiBody.body_title_1, ArticleMultiBody.body_text_1 FROM zahra.articles AS Article
LEFT JOIN zahra.categories AS Category ON (Article.category_id = Category.id)
LEFT JOIN zahra.recipes AS Recipe ON (Recipe.article_id = Article.id)
LEFT JOIN zahra.article_multi_bodies AS ArticleMultiBody ON (ArticleMultiBody.article_id = Article.id) ORDER BY Article.title"
deltaQuery="SELECT Article.id, Article.title, Article.sub_title, Article.category_id, Article.section_title, Article.section_body, Category.id as cat_id, Category.name as cat_name, Recipe.id as recipe_id, Recipe.recipe_title, ArticleMultiBody.id as multi_id, ArticleMultiBody.body_title_1, ArticleMultiBody.body_text_1 FROM zahra.articles AS Article LEFT JOIN zahra.categories AS Category ON (Article.category_id = Category.id) LEFT JOIN zahra.recipes AS Recipe ON (Recipe.article_id = Article.id) LEFT JOIN zahra.article_multi_bodies AS ArticleMultiBody ON (ArticleMultiBody.article_id = Article.id) ORDER BY Article.title">
<field column="ID" name="id" />
<field column="TITLE" name="title" />
<field column="SUB_TITLE" name="sub_title" />
<field column="SECTION_TITLE" name="section_title" />
<field column="SECTION_BODY" name="section_body" />
<field column="CATEGORY_ID" name="category_id" />
<field column="CREATED" name="created" dateTimeFormat="Y-m-d h:i:s" />
<field column="KEYWORDS" name="keywords" splitBy="," sourceColName="tagnames" />
</entity>
</document>
我对下面列出的代码有疑问。
(SELECT GROUP_CONCAT(name separator ',') FROM tags JOIN article_tags ON tags.id = article_tags.tag_id WHERE article_tags.article_id = article.id) as tagnames,
如果我删除此代码,那么我的solr索引效果很好,但是如果我添加这个,我会在索引solr时得到并出错“索引失败。回滚所有更改。”
“tagnames”是生成的新字段,由逗号分隔的值(如标记)组成 例如:食物,健康,健身等
所以我想用这个逗号分隔值配置solr
答案 0 :(得分:1)
仔细检查您的&#34;关键字&#34;字段在架构中定义为multiValued。 &#34;索引失败&#34;通常告诉你原因,并给出一个完整的堆栈跟踪。
此后的实施也可能更适合您尝试的操作。 请注意我删除了你的&#34;组concat&#34;完全查询并将其添加为下面的实体。仔细检查联接和字段名称,我只根据您的命名假设连接。这样您就不会进行额外的连接 - 每行的分割操作
<dataSource name="db2" type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/website"
user="webname"
password="123456"/>
<document name="content">
<entity name="web"
transformer="RegexTransformer"
query="SELECT
Article.id, Article.title, Article.sub_title, Article.category_id,
Article.section_title, Article.section_body, Category.id as cat_id,
Category.name as cat_name, Recipe.id as recipe_id, Recipe.recipe_title, ArticleMultiBody.id as multi_id,
ArticleMultiBody.body_title_1, ArticleMultiBody.body_text_1 FROM zahra.articles AS Article
LEFT JOIN zahra.categories AS Category ON (Article.category_id = Category.id)
LEFT JOIN zahra.recipes AS Recipe ON (Recipe.article_id = Article.id)
LEFT JOIN zahra.article_multi_bodies AS ArticleMultiBody ON (ArticleMultiBody.article_id = Article.id) ORDER BY Article.title"
deltaQuery="SELECT article.id, article.title, article.sub_title, article.category_id, article.section_title, article.section_body, category.id AS cat_id, category.name AS cat_name, recipe.id AS recipe_id, recipe.recipe_title, articlemultibody.id AS multi_id, articlemultibody.body_title_1, articlemultibody.body_text_1 FROM zahra.articles AS Article LEFT JOIN zahra.categories AS CATEGORY ON (Article.category_id = CATEGORY.id) LEFT JOIN zahra.recipes AS Recipe ON (Recipe.article_id = Article.id) LEFT JOIN zahra.article_multi_bodies AS ArticleMultiBody ON (ArticleMultiBody.article_id = Article.id) ORDER BY Article.title">
<field column="ID" name="id"/>
<field column="TITLE" name="title"/>
<field column="SUB_TITLE" name="sub_title"/>
<field column="SECTION_TITLE" name="section_title"/>
<field column="SECTION_BODY" name="section_body"/>
<field column="CATEGORY_ID" name="category_id"/>
<field column="CREATED" name="created" dateTimeFormat="Y-m-d h:i:s"/>
<field column="KEYWORDS" name="keywords" splitBy="," sourceColName="tagnames"/>
<entity name="keywords"
pk="ARTICLE_ID"
query="SELECT name FROM tags JOIN article_tags ON tags.id = article_tags.tag_id WHERE article_tags.article_id = '${web.ID}'">
<field column="KEYWORDS" name="keywords"/>
</entity>
</entity>
</document>