Thanks for many people answer my question and gave me considerable opionions 
and suggestion. I'd like to share what these helps come out here.

Installing Solarium
=====================
# Under Windows
1. Solarium needs php 5.3.3 or up (5.3.4 is recommended). Make sure you install 
correct php engine and make sure php cli executable correctly. Run php cli, if 
there're any error(s)/warning(s), you won't be able to install composer (cause 
the composer setup exe will forbid running further). So try to eliminate these 
error(s)/warning(s), if any (In my case, I have a warning on imagick.dll, so I 
go to php.ini and comment out that extension.) 
2. Download Composer-Setup.exe from https://getcomposer.org (or 
http://getcomposer.org/Composer-Setup.exe).
3. Double-click exe file, follow the instructions and install it ok. It doesn't 
give you chance to change installed folder. I have Win7 64bit and the installed 
folder is c:\ProgramData\composer, setup will add it the PATH environment 
variable).
4.  At this time, you should be able to open a DOS windows and run 'compose' 
ok, so go ahead and open a DOS window, 'cd' to your web root folder (In my 
case, it's c:\appserv\www). Create a subfolder 'solarium'. 'cd' into it.
5. Create a text file named 'composer.json' with following contents: (Current 
newest stable version is 3.6.0)
{
  "require": {
    "solarium/solarium": "3.6.0"
  }
}
    then run 'composer install'. It'll show a lot of message. Be patient and 
when it's done, the last message is normally be ' Generating autoload files'. 
If everything ok, you'll see a file 'composer.lock' and a folder 'vendor'.
6. Congratulation! You just install Solarium ok.
#Under CentOS
1. As said above, prepare correct php version and run php cli ok.
2. Make folder, say /local/composer, cd into it, and make a subfolder 'bin'.cd 
to it.
3. Run 'curl https://getcomposer.org/installer | php'. Wen it's done, run 'mv 
composer.phar composer' (Note: .phar is a php archive executable).
4. 'cd' to your web root folder (In my case, it's /local/htdocs). Create a 
subfolder 'solarium'. 'cd' to it.
5. Create a file named 'composer.json' and its contents as described above. Run 
'/local/composer/bin/composer install'. Be patient and when it's done, it will 
also show 'Generating autoload files' as last message.
6. Again, congratulation! You install Solarium ok.

Checking installation
=======================
#Under Windows
1. 'cd' to that geneated 'vendor' folder. 'cd' into 
vendor\solarium\solarium\examples.
2.  Create a file named 'config.php' with following contents:
<?php
$config = array(
    'endpoint' => array(
        'localhost' => array(
            'host' => '127.0.0.1',
            'port' => 8080,
            'core' => 'collection1',
            'path' => '/solr/',
        )
    )
);
 but replace some values according your Solr server environment. (In my case, 
'localhost' is just a id name we can give on will, so I change it to 'mediaSE'. 
My mediaSE service url is http://10.18.1.237:8983/mediaSE/, so I replace 
127.0.0.1 with 10.18.1.237, 8080 with 8983, /solr/ with /mediaSE/. I don't have 
a core due to mediaSE is Solr 1.4, so I comment out 'core'=>' line.)
3. Edit init.php by change that requre statement to 'require 
__DIR__.'/../../../../vendor/autoload.php'; (i.e. make sure there're 4 ../ 
beofre vendor, i.e. make it point to correct folder that contains autoload.php).
4. Use your php to run, eith cli or web, 1.1-check-solarium-and-ping.php 
script. If things ok, you'll see message such as:
Solarium library version: 3.2.0 - Ping query successful<br/><pre>array(1) {
 ["status"]=>
 string(2) "OK"
}
(Note: For v3.6.0, it shows incorrect verison '3.4.0' which is already 
confirmed as a bug anf fixed, see: 
https://github.com/solariumphp/solarium/issues/428)
#Under CentOS:
1. Just repeat above steps except change folder delimiter \ to /.

To use Solarium in PHP
=================================
I'll just state some important things here. Can't provide intuitive tutorial, 
just have no time for now!
1. Put in 'require ....../autoload.php' statement. Make sure the ...... part 
point to correct folder that contains autoload.php.
2. 'new' Solarium\Client object first. Say the variable name is $client.
3. Use configuration mode, i.e. create a query config array variable, say its 
name is $config,  and '$client->createSelect($config)' to create a 'query' 
object. -OR-
    Use standard mode, i.e. '$client->createSelect()' only, i.e. without any 
argument, to create a 'query' object.
    Say the query object's variable name is $query.
4. Use $query->setXXX methods (please see the official document to see what XXX 
can be) to set necessary values.
5. Issue '$result = $client->select($query)' statement to execute query.
6. You can check if there're any document(s) returned by checking value of 
$result->getNumFound();.
7. If there're any document(s) returned, $result will essentially be an array 
of document object. Use 'foreach' to iterate it.
8. document object is essentially array of field. Say its variable name is 
$doc. You can access field by 3 ways:
    a> Use 'foreach' to iterate it.
    b> Use $doc['fieldname'] to get specific field, e.g. $doc['ID'].
    c> Use $doc->fieldname to get specfic field, e.g. $doc->ID.

How to paginate in PHP
===================================
1. Basically, just use $qurey->setStart(...)->setRows(...) in loop by setting 
appropriate start row offset and pagination row size for your pagination.
2. More advanced, you can try write reuse object codes as shown in official 
document and do pagination to save memory and prevent more GC in php engine.

That's all for now. Rest will be your own homework.

Scott Chu,scott....@udngroup.com
2016/6/2 (週四)
----- Original Message ----- 
From: Shawn Heisey 
To: solr-user 
CC: 
Date: 2016/5/31 (週二) 02:57
Subject: Re: Recommended api/lib to search Solr using PHP


On 5/30/2016 12:32 PM, GW wrote: 
> I would say look at the urls for searches you build in the query tool 
> 
> In my case 
> 
> http://172.16.0.1:8983/solr/#/products/query 
> 
> When you build queries with the Query tool, for example an edismax query, 
> the URL is there for you to copy. 
> Use the url structure with curl in your programming/scripting. The results 
> come back as REST data. 
> 
> This is what I do with PHP and it's pretty tight. 

Be careful with URLs in the admin UI. 

URLs with "#" in them will *only* work in a browser. They are not the 
REST endpoints. 

When you run a query in the admin UI, it will give you a URL to make the 
same query, but it will NOT be the URL in the address bar of the 
browser. There is a link right above the query results. 

Thanks, 
Shawn 



----- 
未在此訊息中找到病毒。 
已透過 AVG 檢查 - www.avg.com 
版本: 2015.0.6201 / 病毒庫: 4591/12328 - 發佈日期: 05/30/16

Reply via email to