solr search indexing to search test from comma seperated value generated using GROUP_CANCAT

StackOverflow https://stackoverflow.com/questions/23360871

  •  11-07-2023
  •  | 
  •  

Domanda

I want to integrate solr search in cakephp, everything is working fine with query but when I added GROUP_CONCATE in my mysql query then I am unable to index my solr search my code is listed below

<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>

I have problem with this code listed below.

 (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,

if I remove this code then my solr index works very well, but if I add this I get and error while indexing solr "Indexing failed. Rolled back all changes."

"tagnames" is the new field generated which consist of comma seperated values like tags eg: Food, Health, Fitness, etc

so i want to configure solr with this comma seperated values

È stato utile?

Soluzione

double check that your "keywords" field is defined as multiValued in the schema. "Indexing Failed" generally tells you the reason, and gives a full stack trace as well.

also this following implementation might work better for what you are trying to do. Notice I removed your "group concat" query completely and added it as an entity below. Double check the joins and field names, I've only assumed connections based on your naming. This way you are not doing the additional concatenate - split action for each and every row

<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>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top