Я использую Solr 9.4.1 и Solarium 6.3.5.
Читая документацию, я думаю, что правильно кодирую реализацию, но мои документы не создаются в Solr как отношения родитель/потомок . Разве это не работает, и мне нужно изменить критерии поиска, чтобы работать с плоским массивом? Я вижу, что в Solr все записи имеют ключ root, и в случае родительской записи он соответствует своему собственному идентификатору, а дочерние записи соответствуют своему родительскому идентификатору. Но это единственная ссылка, говорящая мне, что это сработало.
Вот мой код, надеюсь, кто-то, кто понимает Solr/Solarium лучше, чем я вижу проблему.
public function syncForum()
{
$client = $this->solrclient;
$update = $client->createUpdate();
$db = db_connect();
// Create arrays to store topic and comment documents
$topicQuery = $db->query("SELECT
forum_topics.id AS topic_id,
forum_topics.topic_subject AS topic_subject,
forum_topics.topic_message AS topic_message,
forum_topics.created_at AS created_at,
forum_categories.title AS forum_category,
users.username AS topic_author
FROM
forum_topics
INNER JOIN forum_posts ON forum_posts.post_topic = forum_topics.id
LEFT JOIN users ON users.id = forum_posts.post_by
LEFT JOIN forum_categories ON forum_categories.id = forum_topics.topic_cat");
$topicResult = $topicQuery->getResultArray();
$documentArray = [];
foreach ($topicResult as &$topic) {
//Loop through topics and create a topic document
$document = $update->createDocument();
$document->id = $topic['topic_id'];
$document->topic_subject = $topic['topic_subject'];
$document->topic_message = $topic['topic_message'];
$document->category = $topic['forum_category'];
$document->author = $topic['topic_author'];
// $document->_root_ = 'true';
$topicDate = $topic['created_at'];
$dateTime = new \DateTime($topicDate);
$document->created_at = $dateTime->format("Y-m-d\TH:i:s\Z");
$documentArray[] = $document;
//For each topic, loop through the comments and create a comment document
$commentQuery = $db->query("SELECT forum_posts.id, forum_posts.post_content AS comment_message, forum_posts.created_at, users.username AS author
FROM forum_posts
LEFT JOIN users ON users.id = forum_posts.post_by
WHERE post_topic =" . $topic['topic_id']);
$comments = $commentQuery->getResultArray();
$commArray = [];
foreach ($comments as $i => $comment) {
$commArray[$i]['id'] = $comment['id'];
$commArray[$i]['comment_message'] = $comment['comment_message'];
$commArray[$i]['author'] = $comment['author'];
$originalDate = $comment['created_at'];
$dateTime = new \DateTime($originalDate);
$formattedDate = $dateTime->format("Y-m-d\TH:i:s\Z");
$commArray[$i]['created_at'] = $formattedDate;
}
$document->childdocs = $commArray;
}
// add the documents and a commit command to the update query
$update->addDocuments($documentArray);
$update->addCommit();
// this executes the query and returns the result
$result = $client->update($update);
// Output status information
echo "Status: " . $result->getStatus() . " | Query Time: " . $result->getQueryTime() . PHP_EOL;
}
Подробнее здесь: https://stackoverflow.com/questions/778 ... -documents
Solr — получение вложенных документов ⇐ Php
Кемеровские программисты php общаются здесь
1736685673
Anonymous
Я использую Solr 9.4.1 и Solarium 6.3.5.
Читая документацию, я думаю, что правильно кодирую реализацию, но мои документы не создаются в Solr как отношения родитель/потомок . Разве это не работает, и мне нужно изменить критерии поиска, чтобы работать с плоским массивом? Я вижу, что в Solr все записи имеют ключ root, и в случае родительской записи он соответствует своему собственному идентификатору, а дочерние записи соответствуют своему родительскому идентификатору. Но это единственная ссылка, говорящая мне, что это сработало.
Вот мой код, надеюсь, кто-то, кто понимает Solr/Solarium лучше, чем я вижу проблему.
public function syncForum()
{
$client = $this->solrclient;
$update = $client->createUpdate();
$db = db_connect();
// Create arrays to store topic and comment documents
$topicQuery = $db->query("SELECT
forum_topics.id AS topic_id,
forum_topics.topic_subject AS topic_subject,
forum_topics.topic_message AS topic_message,
forum_topics.created_at AS created_at,
forum_categories.title AS forum_category,
users.username AS topic_author
FROM
forum_topics
INNER JOIN forum_posts ON forum_posts.post_topic = forum_topics.id
LEFT JOIN users ON users.id = forum_posts.post_by
LEFT JOIN forum_categories ON forum_categories.id = forum_topics.topic_cat");
$topicResult = $topicQuery->getResultArray();
$documentArray = [];
foreach ($topicResult as &$topic) {
//Loop through topics and create a topic document
$document = $update->createDocument();
$document->id = $topic['topic_id'];
$document->topic_subject = $topic['topic_subject'];
$document->topic_message = $topic['topic_message'];
$document->category = $topic['forum_category'];
$document->author = $topic['topic_author'];
// $document->_root_ = 'true';
$topicDate = $topic['created_at'];
$dateTime = new \DateTime($topicDate);
$document->created_at = $dateTime->format("Y-m-d\TH:i:s\Z");
$documentArray[] = $document;
//For each topic, loop through the comments and create a comment document
$commentQuery = $db->query("SELECT forum_posts.id, forum_posts.post_content AS comment_message, forum_posts.created_at, users.username AS author
FROM forum_posts
LEFT JOIN users ON users.id = forum_posts.post_by
WHERE post_topic =" . $topic['topic_id']);
$comments = $commentQuery->getResultArray();
$commArray = [];
foreach ($comments as $i => $comment) {
$commArray[$i]['id'] = $comment['id'];
$commArray[$i]['comment_message'] = $comment['comment_message'];
$commArray[$i]['author'] = $comment['author'];
$originalDate = $comment['created_at'];
$dateTime = new \DateTime($originalDate);
$formattedDate = $dateTime->format("Y-m-d\TH:i:s\Z");
$commArray[$i]['created_at'] = $formattedDate;
}
$document->childdocs = $commArray;
}
// add the documents and a commit command to the update query
$update->addDocuments($documentArray);
$update->addCommit();
// this executes the query and returns the result
$result = $client->update($update);
// Output status information
echo "Status: " . $result->getStatus() . " | Query Time: " . $result->getQueryTime() . PHP_EOL;
}
Подробнее здесь: [url]https://stackoverflow.com/questions/77892003/solr-get-nested-documents[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия