/** * Commit the search and close the connection. * @return void */ public function commit() { try { $this->client->commit(); } catch (Exception $e) { } }
/** * Indexes the given entity * * @param object $entity */ public function indexEntity($entity) { $document = $this->createSolrDocument($entity); $this->client->addDocument($document); $this->client->commit(); $this->fields = $this->getEntityFields(get_class($entity)); }
/** * @param \SolrInputDocument $doc */ private function addDocumentToIndex($doc) { try { $updateResponse = $this->solrClient->addDocument($doc); $this->solrClient->commit(); } catch (\Exception $e) { $errorEvent = new ErrorEvent(null, null, 'add-document'); $errorEvent->setException($e); $this->eventManager->handle(EventManager::ERROR, $errorEvent); } }
<?php include "bootstrap.php"; $options = array('hostname' => SOLR_SERVER_HOSTNAME, 'login' => SOLR_SERVER_USERNAME, 'password' => SOLR_SERVER_PASSWORD, 'port' => SOLR_SERVER_PORT, 'path' => SOLR_SERVER_PATH); $client = new SolrClient($options); $update_response = $client->commit(true, false, false); $response = $update_response->getRawRequest(); print_r($response);
<?php define('SOLR_SERVER_HOSTNAME', 'localhost'); define('SOLR_SERVER_PORT', '8983'); define('SOLR_SERVER_PATH', 'solr/europeana'); $options = array('hostname' => SOLR_SERVER_HOSTNAME, 'port' => SOLR_SERVER_PORT, 'path' => SOLR_SERVER_PATH); $client = new SolrClient($options); $client->deleteByQuery("*:*"); $client->commit();
private function _process_import_order($order_table, $order_id, $start_time, $end_time, $limit, $offset) { $total = $this->solr_order_model->fetch_order_count_by_updated($order_table, $start_time, $end_time); $successful = TRUE; $options = array('hostname' => SOLR_SERVER_HOSTNAME, 'port' => SOLR_SERVER_PORT); echo 'table: ' . $order_table, "\n"; echo 'total: ' . $total, "\n"; do { echo 'off set: ' . $offset, "\n"; $orders = $this->solr_order_model->fetch_orders_by_updated($order_table, $start_time, $end_time, $limit, $offset); $docs = array(); foreach ($orders as $order) { $client = new SolrClient($options); $doc = new SolrInputDocument(); $doc->addField('id', $order_table . ':' . $order->{$order_id}); $skus = explode(',', $order->sku_str); foreach ($skus as $sku) { $doc->addField('skus', $sku); } $doc->addField('list_datetime', $order->list_date . 'T' . $order->list_time . "Z"); $doc->addField('buyer_name', $order->name); $doc->addField('buyer_id', $order->buyer_id); $doc->addField('list_type', $order->list_type); $doc->addField('payment_status', $order->payment_status); $doc->addField('subject', $order->subject); $doc->addField('currency', $order->currency); $doc->addField('gross', make_number($order->gross, 0)); $doc->addField('fee', make_number($order->fee, 0)); $doc->addField('net', make_number($order->net, 0)); $doc->addField('time_zone', $order->time_zone); $doc->addField('note', $order->note); $doc->addField('buyer_email', $order->from_email); $doc->addField('company_email', $order->to_email); $doc->addField('transaction_id', $order->transaction_id); $doc->addField('payment_type', $order->payment_type); $doc->addField('shipping_address', $order->shipping_address); $doc->addField('address_status', $order->address_status); $item_titles = explode_item_title($order->item_title_str); foreach ($item_titles as $item_title) { $doc->addField('item_titles', $item_title); } $item_ids = explode(',', $order->item_id_str); foreach ($item_ids as $item_id) { $doc->addField('item_ids', $item_id); } $doc->addField('item_url', $order->item_url); $doc->addField('closing_date', $order->closing_date); $doc->addField('invoice_number', $order->invoice_number); $doc->addField('address_line_1', $order->address_line_1); $doc->addField('address_line_2', $order->address_line_2); $doc->addField('town_city', $order->town_city); $doc->addField('state_province', $order->state_province); $doc->addField('country', $order->country); $doc->addField('zip_code', $order->zip_code); $doc->addField('contact_phone_number', $order->contact_phone_number); $doc->addField('income_type', $order->income_type); $qties = explode(',', $order->qty_str); foreach ($qties as $qty) { //$doc->addField('qties', make_number($qty)); } $doc->addField('description', $order->descript); $doc->addField('input_datetime', to_utc_format($order->input_date)); $doc->addField('input_user', $order->input_user); $doc->addField('order_status', make_number($order->order_status)); $doc->addField('check_date', to_utc_format($order->check_date)); $doc->addField('check_user', $order->check_user); $doc->addField('print_label_date', to_utc_format($order->print_label_date)); $doc->addField('label_content', $order->label_content); $doc->addField('item_no', $order->item_no); $doc->addField('print_label_user', $order->print_label_user); $doc->addField('ship_confirm_date', to_utc_format($order->ship_confirm_date)); $doc->addField('ship_confirm_user', $order->ship_confirm_user); $doc->addField('ship_weight', make_number($order->ship_weight, 0)); $doc->addField('ship_remark', $order->ship_remark); $doc->addField('track_number', $order->track_number); $doc->addField('shipping_code', $order->is_register, 0); $doc->addField('cost', make_number($order->cost, 0)); $doc->addField('cost_date', to_utc_format($order->cost_date)); $doc->addField('cost_user', $order->cost_user); $product_costs = explode(',', trim($order->product_cost, ',')); foreach ($product_costs as $product_cost) { $doc->addField('product_costs', make_number($product_cost, 0)); } $doc->addField('product_total_cost', $order->product_cost_all); $doc->addField('shipping_cost', make_number($order->shipping_cost, 0)); $doc->addField('return_date', to_utc_format($order->return_date)); $doc->addField('return_remark', $order->return_remark); $doc->addField('return_user', $order->return_user); $doc->addField('return_why', $order->return_why); $doc->addField('return_order', $order->return_order); $doc->addField('return_cost', make_number($order->return_cost, 0)); $doc->addField('sys_remark', $order->sys_remark); $doc->addField('order_receive_date', $order->order_receive_date); $doc->addField('email_status', $order->email_status); $doc->addField('stock_user_id', make_number($order->stock_user_id)); $doc->addField('saler_id', make_number($order->saler_id)); $purchaser_ids = explode(',', $order->purchaser_id_str); foreach ($purchaser_ids as $purchaser_id) { $doc->addField('purchaser_ids', make_number($purchaser_id)); } $developer_ids = explode(',', $order->developer_id); foreach ($developer_ids as $developer_id) { $doc->addField('developer_ids', make_number($developer_id)); } $doc->addField('trade_fee', make_number($order->trade_fee, 0)); $doc->addField('listing_fee', make_number($order->listing_fee, 0)); $doc->addField('profit_rate', make_number($order->profit_rate, 0)); $doc->addField('refund_verify_status', $order->refund_verify_status); $doc->addField('refund_verify_type', $order->refund_verify_type); $doc->addField('refund_verify_content', $order->refund_verify_content); $refund_duties = explode(',', $order->refund_duty); foreach ($refund_duties as $refund_duty) { $doc->addField('refund_duties', $refund_duty); } $refund_skus = explode(',', $order->refund_sku_str); foreach ($refund_skus as $refund_sku) { $doc->addField('refund_skus', $refund_sku); } $docs[] = $doc; } try { if (!empty($docs)) { $response = $client->addDocuments($docs); $client->commit(); } } catch (SolrException $e) { $successful = FALSE; var_dump($e); break; } $offset += $limit; } while ($offset < $total); return $successful; }
public function deleteKeywordsintoSolrDocument($id_news, $type) { try { $this->config->load('solr'); $solr = $this->config->item('solr'); $options = array('hostname' => $solr['SOLR_SERVER_HOSTNAME'], 'login' => $solr['SOLR_SERVER_USERNAME'], 'password' => $solr['SOLR_SERVER_PASSWORD'], 'port' => $solr['SOLR_SERVER_PORT'], 'path' => 'solr/keywords'); $client = new SolrClient($options); $client->deleteByQuery("id_news:{$id_news} AND type:{$type}"); return $client->commit(); } catch (Exception $e) { return FALSE; } }
<?php $core = 'techknowledgy_core'; #$core = 'demo'; $options = array('hostname' => 'localhost', 'port' => 8983, 'timeout' => 10, 'path' => '/solr/' . $core); $client = new SolrClient($options); if (!$client->ping()) { exit('Solr service not responding.'); } else { print "Worked!"; } # CODE FOR CLEARING CORE OF ALL DOCS ===> $deleteResponse = $client->deleteByQuery("*.htm*"); $client->commit(true); print_r($deleteResponse->getResponse()); # <=== END OF CODE FOR CLEARING CORE OF ALL DOCS # CODE FOR ADDING NEW DOC ===> #$doc = new SolrInputDocument(); #$doc->addField('id', '090945'); #$doc->addField('link', 'www.test.com'); #$doc->addField('text', 'this is another test'); #$updateResponse = $client->addDocument($doc); #$client->commit(true); #print_r($updateResponse->getResponse()); # <=== END OF ADDING NEW DOC CODE # QUERYING DOCUMENTS CODE ===> #$query = new SolrQuery(); #$query->setQuery('technology'); #$query->setStart(0); #$query->setRows(50); #$query->addField('url')->addField('title')->addField('host')->addField('content');
public function addListKeywordtoSolr() { try { $keywords = $this->m_backend->jqxGets('keywords'); if (empty($keywords) === FALSE) { $this->config->load('solr'); $solr = $this->config->item('solr'); $options = array('hostname' => $solr['SOLR_SERVER_HOSTNAME'], 'login' => $solr['SOLR_SERVER_USERNAME'], 'password' => $solr['SOLR_SERVER_PASSWORD'], 'port' => $solr['SOLR_SERVER_PORT'], 'path' => 'solr/keywords'); $client = new SolrClient($options); foreach ($keywords as $keyword) { $doc = new SolrInputDocument(); $doc->addField('id', $keyword['id']); $doc->addField('name', $keyword['name']); $doc->addField('alias', $keyword['alias']); $doc->addField('id_news', $keyword['id_news']); $doc->addField('type', $keyword['type']); $doc->addField('priority', $keyword['priority']); $updateResponse = $client->addDocument($doc); $client->commit(); } } else { return FALSE; } } catch (Exception $e) { return FALSE; } }