PHP's solr operation classes and demo
php’s solr operation class and demo
1. Solr class
'127.0.0.1','port' => '8080'); /** * 设置solr库选择 * @param $core string 库名称 */ public static function setCore($core){ if($core) self::$options['path']='solr/'.$core; } /** * 增加solr索引 * @param $fieldArr 索引字段及值 * @return bool true */ public static function addDocument($fieldArr=array()){ $client = new SolrClient(self::$options); $doc = new SolrInputDocument(); foreach($fieldArr as $k => $v){ $doc->addField($k,$v); } $client->addDocument($doc); $client->commit(); return true; } /** * 删除索引 * @param $id 主键id id可以为数组形式,应用于多选的情况 * @return bool true */ public static function delDocument($ids){ $client = new SolrClient(self::$options); if(is_array($ids)) $client->deleteByIds($ids); else $client->deleteById($ids); $client->commit(); return true; } /** * 查询数据 * @param $qwhere 关键字 * @param $fqwhere 附加条件,根据范围检索,适用于数值型 * @param $getField 查询字段 * @param $sort 排序 array('duration'=>'asc') asc:升序,desc:降序 * @param $pageindex 查询页数 * @param $pagesize 每页显示条数 */ public static function selectQuery($qwhere=array(),$fqwhere=array(),$getField=array(),$sort=array(),$pageindex=1,$pagesize=20){ $client = new SolrClient(self::$options); $query = new SolrQuery(); $sel = ''; foreach($qwhere as $k => $v){ // $sel .= ' +'.$k.':'.$v; $sel = "{$k} : \"{$v}\""; } $query->setQuery($sel); //关键字检索 //附加条件,根据范围检索,适用于数值型 if($fqwhere){ $query->setFacet(true); foreach($fqwhere as $k => $v) $query->addFacetQuery($v); //$query->addFacetQuery('price:[* TO 500]'); } //查询字段 if($getField){ foreach($getField as $key => $val) $query->addField($val); } //排序 if($sort){ foreach($sort as $k => $v){ if($v == 'asc') $query->addSortField($k,SolrQuery::ORDER_ASC); elseif($v == 'desc') $query->addSortField($k,SolrQuery::ORDER_DESC); } } //分页 $query->setStart(self::getPageIndex($pageindex,$pagesize)); $query->setRows($pagesize); $query_response = $client->query($query); $response = $query_response->getResponse(); return $response; } /** * 分页数据处理 */ private static function getPageIndex($pageindex,$pagesize){ if($pageindex<=1) $pageindex = 0; else $pageindex = ($pageindex-1)*$pagesize; return $pageindex; } }
2. Operation demo
"wang jing jie", ); print_r(phpSolr::selectQuery($qwhere)); //添加 $fieldArr = array( "id" => 15, "username" => "si sheng chao", "usertype" => 1, "last_update_time" => "2016-01-05T03:35:13Z", ); phpSolr::addDocument($fieldArr); //删除 //phpsolr::delDocument(15);
The above introduces the php’s solr operation class and demo, including aspects Content, please pay attention to the PHP Chinese website (www.php.cn) for more related content!
Related articles:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The word demo is no longer unfamiliar to friends who like to sing, but many users who have never been exposed to it are curious about what demo means. Now let’s take a look at the meaning of the demo brought by the editor. What does demo mean? Answer: Demo tape. 1. The pronunciation of demo is ['deməʊ] in English and ['demoʊ] in America. 2. Demo is the abbreviation of "demonstration", which generally refers to the preliminary effect of listening to a song before it is officially recorded. 3. Demo is used as a noun to refer to sample tapes and sample records. The meaning of verb is trial (especially software), demonstration and demonstration;

Simple use of pythonrandom library demo When we need to generate random numbers or randomly select elements from a sequence, we can use Python's built-in random library. The following is an annotated example that demonstrates how to use the random library: #Import random library importrandom #Generate a random decimal between 0 and 1 random_float=random.random()print(random_float)#Generate a random decimal within the specified range Random integer (including endpoints) random_int=random.randint(1,10)print(random_int)#

Solr is a Lucene-based search engine that can be used to implement full-text search. Using Solr in PHP for full-text search can help us quickly query relevant data through keywords and improve the accuracy and reliability of search results. This article will introduce how to use Solr in PHP for full-text search. 1. Installation and configuration of Solr First, we need to install Solr and the Solr extension of PHP on the server. For Solr installation steps, please refer to Solr’s official documentation.

With the development of the Internet and the explosive growth of information, the amount of information we can now access and obtain is very large. Whether it is information obtained from web pages, documents, or daily life, it requires an efficient way to process and manage it. Full-text search is a very efficient and commonly used method. It can locate and extract the information we need through keywords or phrases, and Solr is a tool that is very suitable for full-text search development. This article will introduce the basic concepts of Solr and how to use it in Java API development.

Realme turned heads recently when it announced 300W fast-charging for its supposedGT7 Pro(as detailed in previous leaks). It's not the first brand to make such an announcement, though - Xiaomi has also been teasing its 300W charging for a while now.

Beego is a fast Go language web framework, and Solr is a Lucene-based search and query server. Using the two together can provide efficient search capabilities to web applications. This article will introduce how to use Solr for search and query in Beego. Step 1: Install Solr Before you start using Solr, you need to install Solr. Solr can be downloaded and downloaded from the official website (https://lucene.apache.org/solr/)

1. Import Lombok's dependency org.projectlomboklombok1.18.62 in pom.xml in the created springboot project. Install the Lombok plug-in 3. Create a package of the entity class at the same level as the main startup class, create the entity class in the package, and Use Lombokpackagecom.hxy.bean;importcom.fasterxml.jackson.annotation.JsonFormat;importlombok.AllArgsConstructor;importlombok.Data;importlom on entity classes

0x00 Introduction Solr is an independent enterprise-level search application server that provides an API interface similar to Web-service. Users can submit XML files in a certain format to the search engine server through http requests to generate indexes; they can also make search requests through HttpGet operations and get returned results in XML format. The vulnerability stems from the security risk in the ENABLE_REMOTE_JMX_OPTS configuration option in the default configuration file solr.in.sh. ENABLE_REMOTE_JMX_OPTS= exists in the built-in configuration file solr.in.sh of versions 8.1.1 and 8.2.0 of ApacheSolr.
