Solr — получение вложенных документовPhp

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Solr — получение вложенных документов

Сообщение 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;
}


Подробнее здесь: https://stackoverflow.com/questions/778 ... -documents
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»