Link to the original text :http://www.ibm.com/developerworks/cn/opensource/os-php-apachesolr/

  http://blog.csdn.net/hzcyclone/article/details/7006354

1、 install solr( Download address :http://www.apache.org/dyn/closer.lua/lucene/solr/6.0.0)

2、 install php Of solr Expand ( Download address :http://pecl.php.net/package/solr)

3、 download phpsolrclient Code ( The most robust implementation is Donovan Jimenez Of PHP Solr Client, Download address :http://code.google.com/p/solr-php-client/downloads/list)

4、 Use code examples :

<?php
include("Apache/Solr/Service.php");
// Connect Solr The server
$solr = new Apache_Solr_service('localhost' , '8983' ,'/solr');
if( !$solr->ping() ) {
echo'Solr server not responding';
exit;
}
$data = array(
array(
'id' => 'EN80922032',
'name' => ' Men's polished straight casual jeans ',
'brand' => 'ENERGIE',
'cat' => ' A pair of jeans ',
'price' => '1870.00'
),
array(
'id' => 'EN70906025',
'name' => ' brand LOGO Lapel zipper jacket ',
'brand' => 'ENERGIE',
'cat' => ' coat ',
'price' => '1680.00'
),
);
// Add index data
$documents = array();
foreach($data as $key => $value) {
$part =new Apache_Solr_Document();
foreach($value as $key2 =>$value2) {
$part->$key2 =$value2;
}
$documents[] = $part;
}
$solr->addDocuments( $documents );
$solr->commit();
$solr->optimize();
// Query index $solr->search( Field : keyword , Start , Each page shows , Sort )
$offset = 0;
$limit = 10;
$sort = 'price asc';
$rs = $solr->search("brand:ENERGIE" , $offset ,$limit,array('sort' => $sort));
if($rs->response->numFound> 0) {
foreach($rs->response->docs as $doc) {
echo $doc->id.'|'.$doc->name.'|'.$doc->brand.'|'.$doc->price.'<br>';
}
}
?>

Use PHP and Apache Solr More articles about enterprise search

  1. SOLR Build enterprise search platform

    One . SOLR Build enterprise search platform   Running environment :  Run container :Tomcat6.0.20  Solr edition :apache-solr-1.4.0  Word segmentation is :mmseg4j-1.6.2  Thesaurus :sogou-dic ...

  2. utilize SOLR Build enterprise search platform And ——MultiCore

    Solr Multicore yes solr 1.3 New features . The aim is to solr example , There can be multiple search applications . Let's start with solr A given example run out . This article is based on < utilize SOLR Build a company ...

  3. utilize SOLR Build enterprise search platform And —— Mode configuration Schema.xml

    source :http://blog.csdn.net/awj3584/article/details/16963525 schema.xml This configuration file can be downloaded from you solr Package installation decompression Directory \solr\ex ...

  4. utilize SOLR Build enterprise search platform And —— The configuration file

    function solr It's a very simple thing , How to make solr Run your project efficiently , This is not easy . There are too many factors to consider . One of the most important things here is to solr You need to understand . Understand the meaning of each configuration item in the configuration file , In this way, the operation will be like a fish in water ! stay so ...

  5. utilize SOLR Build enterprise search platform And ——solr To configure solrconfig.xml

    source :http://blog.csdn.net/zx13525079024/article/details/25310781 solrconfig.xml The configuration file mainly defines SOLR Some of the processing rules of , Include ...

  6. utilize SOLR Build enterprise search platform And —— function solr

    source :http://blog.csdn.net/zx13525079024/article/details/24806131 This section focuses on the introduction Solr Installation , Actually Solr No installation required . Just download it directly    ...

  7. utilize SOLR Build enterprise search platform And ——Solr Index basic operations

    source :http://blog.csdn.net/zx13525079024/article/details/25367239 Let's take a look at the interface SOLR, Include SOLR Index addition , Query and other basic operations . ...

  8. utilize SOLR Build enterprise search platform And ——solr Query syntax of

      1. First of all, let's say that in my data fields Yes :name, tel, address The default search is name This field , If the data you're looking for happens to be name This field , You don't need to specify the search field name . 2. Inquiry rules ...

  9. Apache Solr use Java Development 、 be based on Lucene Full text search server for

    http://docs.spring.io/spring-data/solr/ Let's first introduce solr: Apache Solr ( pronunciation : SOLer)  It's open source . High performance . use Java Development . be based on Luc ...

Random recommendation

  1. Ubuntu Lower installation Docker

    1. Check the system before installing docker Support for , Install as high a version of the system as possible , such as Ubuntu14.04 etc. , You can check the system information before installation . Docker need 64 Bit machine , Need to run on 3.8 On the kernel above , Operating system support required ...

  2. Use Concurrency Visualizer Optimize performance

    Concurrency Visualizer: https://msdn.microsoft.com/en-us/library/dd537632.aspx?f=255&MSPPError=- ...

  3. eclipse Use tips-Toggle Mark Occurrences Color change

    Toggle Mark Occurrences This function is very easy to use , Can put the selected method / Variables are highlighted where they all appear in this class , It's a very practical function . But the default color is gray , It's very eye damaging . You can change it to your favorite through the following settings ...

  4. 【MySQL】binlog Cache issues and performance

    Before, in the case of no backup Library , Met more than 'max_binlog_cache_size' bytes of storage Error of , Today, I encountered this problem again in the primary and standby replication Last_SQL_Er ...

  5. [ Reprint ] FFmpeg error C4996: ‘avcodec_alloc_frame’: Was declared rejected resolvent

    stay Visual Studio 2013 Write below  FFmpeg  There was an error in the program , Error is as follows : The error code is as follows : The solution is : take  avcodec_alloc_frame()  Replace with  av_frame_alloc ...

  6. turn ---- Asp.net mvc Project paging function

    1. Define a page for Page<T> class 1 /* Examples of use : 2 var pager = new Pager<Article>( 3 this.ControllerContext ...

  7. according to IP The address for IP Details of

    <?php header('Content-Type:text/html; charset=utf-8'); function ip_data() { $ip = GetIP(); $url = ...

  8. High imitation and fine imitation of wechat application ios Source download

    WeChat , exceed 3 Billion people use , Can send voice to friends through mobile network . Text message . expression . Pictures and videos , You can also share photos with your friends . By shaking . Check out the people around , You can make new friends . Use a sweep , You can scan the QR code . bar code . Books and streetscape . ...

  9. Cocos2d-x Way of learning ------(CCCallfunc series )

    CCCallFunc,CCCallFuncN,CCCallFuncND,CCCallFuncO Classes call functions to perform actions , Their use is limited to the parameters of the functions they call CCCallFunc The callback ...

  10. Dynamics CRM Odata QueryUrl Medium SetName problem

    use javasrcipt adopt odata How to access organization services for CRUD In operation ,queryurl The right stitching is key . With the following url For example :"XX/XRMServices/2011/Organizati ...