简体   繁体   中英

how i can do the relation on solarium? like what we can do on SQL by using select and where

This is my code. I want to display the author name with his book. I had uploaded two files to Solr (book, author) and there is column share between the two file ( authid on another file and oAuth on book file). I don't know how can do this process in Solarium?

<?php

require(__DIR__.'/init.php');
htmlHeader();

// create a client instance
$client = new Solarium\Client($config);

// get a select query instance
$query = $client->createSelect();
//be sure to validate and clean your variables
$val1 = htmlentities($_GET['searchSolr']);
//then you can use them in a PHP function. 

$query->createFilterQuery('search')->setQuery(('bk:'). $val1);

// this executes the query and returns the result
$resultset = $client->select($query);

// display the total number of documents found by solr
echo 'عدد نتائج البحث: '.$resultset->getNumFound();

// show documents using the resultset iterator
foreach ($resultset as $document) {

    echo '<hr/><table>';
    echo '<tr><th>اسم الكتاب:</th><td>' . $document->bk[0] . '</td></tr>';
    echo '<tr><th>رقم الكتاب:</th><td>' . $document->bkid[0] . '</td></tr>';
    echo '</table>';
}

htmlFooter();

Solr can't perform regular joins, the only supported functionality for regular joins is to use one side of the join to filter the other side - ie the same as an INNER JOIN. In your case you want information from both sides (the author name and the book title), which just isn't possible with the "join" functionality in Solr.

If you're running Solr in its cloud mode, using a streaming expression can be a solution, but the preferred way to solve this is to just add the name of the author to the book document itself. That way it's part of the data you need for a book (and an author's name usually doesn't change often, so performing updates will be very manageable).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM