How to install Sphinx Search in Ubuntu 16.04

No comments
~~~~~~~~~~~~~~Step 1 — Installing Sphinx~~~~~~~~~~~~~~~~~~

Installing Sphinx on Ubuntu is easy because it's in the native package repository. Install it using apt-get.

    sudo apt-get install sphinxsearch

~~~~~~~~~~~~~~~~Step 2 – Creating the Test Database~~~~~~~~~~~~~~~

Next, we'll set up a database using the sample data in the SQL file provided with the package. This will allow us to test that Sphinx search is working later.

Let's import the sample SQL file into the database. First, log in to the MySQL server shell.

    mysql -u root -p
Enter the password for the MySQL root user when asked. Your prompt will change to mysql>.

Create a dummy database. Here, we're calling it test, but you can name it whatever you want.

    CREATE DATABASE test;

Import the example SQL file.

    SOURCE /etc/sphinxsearch/example.sql;

Then leave the MySQL shell.

    quit

~~~~~~~~~~~~~~~~~~~~~Step 3 – Configuring Sphinx~~~~~~~~~~~~~~~~~~

First, create the sphinx.conf file.

    sudo nano /etc/sphinxsearch/sphinx.conf

Each of these index, searchd, and source blocks are described below. Then, at the end of this step, the entirety of sphinx.conf is included for you to copy and paste into the file.

The source block contains the type of source, username and password to the MySQL server. The first column of the sql_query should be a unique id. The SQL query will run on every index and dump the data to Sphinx index file. Below are the descriptions of each field and the source block itself.

    type: Type of data source to index. In our example, this is mysql. Other supported types include pgsql, mssql, xmlpipe2, odbc, and more.
    sql_host: Hostname for the MySQL host. In our example, this is localhost. This can be a domain or IP address.
    sql_user: Username for the MySQL login. In our example, this is root.
    sql_pass: Password for the MySQL user. In our example, this is the root MySQL user's password.
    sql_db: Name of the database that stores data. In our example, this is test.
    sql_query: The query thats dumps data from the database to the index.

            // full conf file sample given. You have to change all things as your requirment i.e. source name, host,user,pass,db table name etc...
            {
            source src1
              type          = mysql

              sql_host      = localhost
              sql_user      = root                      //////////////////// database username
              sql_pass      = your_root_mysql_password  //////////////////// password
              sql_db        = test                         //////////////////// database name
              sql_port      = 3306

              sql_query     = \
              SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content \
              FROM documents

              sql_attr_uint         = group_id
              sql_attr_timestamp    = date_added
            }
            index test1
            {
              source            = src1                                    /////////same as above source
              path              = /var/lib/sphinxsearch/data/test1        ////////// test1 is indexname. change as your requirement
              docinfo           = extern
            }
            searchd
            {
              listen            = 9306:mysql41
              log               = /var/log/sphinxsearch/searchd.log
              query_log         = /var/log/sphinxsearch/query.log
              read_timeout      = 5
              max_children      = 30
              pid_file          = /var/run/sphinxsearch/searchd.pid
              seamless_rotate   = 1
              preopen_indexes   = 1
              unlink_old        = 1
              binlog_path       = /var/lib/sphinxsearch/data
            }




~~~~~~~~~~~~~~~~~Step 4 — Managing the Index~~~~~~~~~~~~~~

In this step, we'll add data to the Sphinx index and make sure the index stays up to date using cron.

First, add data to the index using the configuration we created earlier.

    sudo indexer --all

    You should get something that looks like the following.

        Output
        Sphinx 2.2.9-id64-release (rel22-r5006)
        Copyright (c) 2001-2015, Andrew Aksyonoff
        Copyright (c) 2008-2015, Sphinx Technologies Inc (http://sphinxsearch.com)

        using config file '/etc/sphinxsearch/sphinx.conf'...
        indexing index 'test1'...
        collected 4 docs, 0.0 MB
        sorted 0.0 Mhits, 100.0% done
        total 4 docs, 193 bytes
        total 0.010 sec, 18552 bytes/sec, 384.50 docs/sec
        total 4 reads, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg
        total 12 writes, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg



In production environments, it is necessary to keep the index up to date. To do that let's create a cronjob. First, open crontab.

    crontab -e



The follow cronjob will run on every hour and add new data to the index using the configuration file we created earlier. Copy and paste it at the end of the file, then save and close the file.

    @hourly /usr/bin/indexer --rotate --config /etc/sphinxsearch/sphinx.conf --all


~~~~~~~~~~~~~~~~~~~~Step 5 — Starting Sphinx~~~~~~~~~~~~~~
By default, the Sphinx daemon is tuned off. First, we'll enable it by changing the line START=no to START=yes in /etc/default/sphinxsearch.

    sudo sed -i 's/START=no/START=yes/g' /etc/default/sphinxsearch

Then, use systemctl to restart the Sphinx daemon.

    sudo systemctl restart sphinxsearch.service
To check if the Sphinx daemon is running correctly, run.

    sudo systemctl status sphinxsearch.service





ALL STEPS AT A GLANCE


1    sudo apt-get install sphinxsearch
2    mysql -u root -p                              // have to give mysql password

3    CREATE DATABASE test;
4    SOURCE /etc/sphinxsearch/example.sql;

5    quit

6    sudo nano /etc/sphinxsearch/sphinx.conf       // copy given sample.conf file to this file

7    sudo indexer --all

8    crontab -e                                  //copy below line and paste it in cronjob and save it.

    @hourly /usr/bin/indexer --rotate --config /etc/sphinxsearch/sphinx.conf --all   

9    sudo sed -i 's/START=no/START=yes/g' /etc/default/sphinxsearch

10    sudo systemctl restart sphinxsearch.service

11    sudo systemctl status sphinxsearch.service

No comments :

Post a Comment

Insert google map in your website php code

No comments
<style>    
  #contact-map {
    height: 500px;
  }
</style>
<div id="contact-map"></div>

<script>
  var map;

  function initMap() {

    var myLatlng = new google.maps.LatLng(your lat,your lng);
    map = new google.maps.Map(document.getElementById('contact-map'), {
      center: myLatlng,
      zoom: 15
    });

    var marker = new google.maps.Marker({
        position: myLatlng,
        title:"TITLE "
    });
    marker.setMap(map);

  }


</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB5O1LcvjU5OnLyfwTr2dmo9zu_1zql_UQ&callback=initMap"
    async defer></script>
 

No comments :

Post a Comment

ADD random new article in joomla through php code

No comments
instruction

1) create a new php file  add code give below.
2) put this file in joomla folder of your project.
3) run this php file.


////////////////////////////////code////////////////////////////////////
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<div id="progress" style="width:500px;border:1px solid #ccc;"></div>
<!-- Progress information -->
<div id="information" style="width"></div>


</body>
</html>

<?php

define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);

if (file_exists(dirname(__FILE__) . '/defines.php')) {
   include_once dirname(__FILE__) . '/defines.php';
}
if (!defined('_JDEFINES')) {
   define('JPATH_BASE', dirname(__FILE__));
   require_once JPATH_BASE.'/includes/defines.php';
}

//define('JPATH_COMPONENT_ADMINISTRATOR', dirname(__FILE__) . "/administrator");
define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_BASE . DS . 'administrator' . DS . 'components' . DS . 'com_content');
require_once JPATH_BASE.'/includes/framework.php';
//$app = JFactory::getApplication('site');
//require_once JPATH_BASE.'/includes/framework.php';


//echo JPATH_BASE. "/administrator/components/com_content/models/article.php";
require_once JPATH_BASE. "/administrator/components/com_content/models/article.php";
                         //administrator/components/com_content/models


$app = JFactory::getApplication('site', array('session' => false));

$total=100;

for($i=0;$i<100;$i++){

    $title_script="title".$i;
    $main_discription="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod";

       $data = array(
          'catid' => 80, //newsarticles
          'title' => $title_script,
          'introtext' =>$main_discription,
          'fulltext' => '',
          'state' => 1,);
     

      $title_script="";
      $main_discription="";
      $new_article = new ContentModelArticle();
      //print_r($data);

      $new_article->save($data);

    // add progress bar
    $percent = intval($i/$total * 100)."%";
    echo '<script language="javascript">
    document.getElementById("progress").innerHTML="<div style=\"width:'.$percent.';background-color:#ddd;\">&nbsp;</div>";
    document.getElementById("information").innerHTML="'.$i.' row(s) processed.";
    </script>';
    // This is for the buffer achieve the minimum size in order to flush data
    echo str_repeat(' ',1024*64);   
    // Send output to browser immediately
    flush();   
    // Sleep one second so we can see the delay
    sleep(1);
    echo '<script language="javascript">document.getElementById("information").innerHTML="Process completed"</script>';
}

?>

////////////////////////////////////////////////////////////////////////////////

No comments :

Post a Comment

progress bar through php

No comments
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<div id="progress" style="width:500px;border:1px solid #ccc;"></div>
<!-- Progress information -->
<div id="information" style="width"></div>


</body>
</html>

<?php
$total=50;
for($i=0;$i<$total;$i++){   

$percent = intval($i/$total * 100)."%";
echo '<script language="javascript">
    document.getElementById("progress").innerHTML="<div style=\"width:'.$percent.';background-color:orange;\">&nbsp;</div>";
    document.getElementById("information").innerHTML="'.$i.' row(s) processed.";
    </script>';

    // This is for the buffer achieve the minimum size in order to flush data
    echo str_repeat(' ',1024*64);

   
// Send output to browser immediately
    flush();
   
// Sleep one second so we can see the delay
    sleep(1);
    echo '<script language="javascript">document.getElementById("information").innerHTML="Process completed"</script>';
}
?>

No comments :

Post a Comment

How to make CSV file from mysql database using PHP

No comments
This example demonstrate how to make csv file form mysql table using php. in this example csv file will contain name, username and email from user table. database connection has been takem dynamically from joomla configuration.php file. you need to change it as your requirement.

<?php
    require_once "configuration.php";

    $config = new JConfig();
    $host = $config->host;
    $db = $config->db;
    $dbprefix = $config->dbprefix;
    $password = $config->password;
    $user = $config->user;

    $con = new mysqli($host,$user,$password, $db);


    $filename = "users.csv";
    $fp = fopen('php://output', 'w');
    $header = array("name","username","email");

        header('Content-type: application/csv');
        header('Content-Disposition: attachment; filename='.$filename);
        fputcsv($fp, $header);

    $query = "SELECT name, username, email FROM jnr6o_users";
    $result = $con->query($query);
    while($row = mysqli_fetch_row($result)) {
            fputcsv($fp, $row);
        }
exit;
?>

No comments :

Post a Comment

How to configure mysql connection dynamically in joomla website.

No comments
How to configure core php-mysql connection dynamically in joomla website form configuration file.

<?php
    require_once "../configuration.php";

    $config = new JConfig();
    $host = $config->host;
    $db = $config->db;
    $dbprefix = $config->dbprefix;
    $password = $config->password;
    $user = $config->user;

    $con = new mysqli($host,$user,$password, $db);

    if ($con->connect_error) {
        die("Connection failed: " . $con->connect_error);
    }
?>

No comments :

Post a Comment

Import data from CSV file to mysql database using PHP

No comments

<?php

$host = "localhost"
$user = username;
$password = database password;
$db =database name;

$con = new mysqli($host,$user,$password, $db);

if ($con->connect_error) {
    die("Connection failed: " . $con->connect_error);
}
?>
<html>
<head>
    <style type='text/css'>
        body
        {
            margin: 0;
            padding: 0;
            background-color:#FFFFFF;
            text-align:center;
        }
        .top-bar
        {
            width: 100%;
            height: auto;
            text-align: center;
            background-color:#FFF;
            border-bottom: 1px solid #000;
            margin-bottom: 20px;
        }
        .inside-top-bar
        {
            margin-top: 5px;
            margin-bottom: 5px;
        }
        .link
        {
            font-size: 18px;
            text-decoration: none;
            background-color: #000;
            color: #FFF;
            padding: 5px;
        }
        .link:hover
        {
            background-color: #FCF3F3;
        }
    </style>

</head>
<body>
    <div class='top-bar'>
        <div class='inside-top-bar'>Import CSV file to mysql table <br><br>
        </div>
    </div>
    <div style='text-align:left; border:1px solid #333333; width:300px; margin:0 auto; padding:10px;'>

        <form name='import' method='post' enctype='multipart/form-data'>
            <input type='file' name='file' /><br />
            <input type='submit' name='submit' value='Submit' />
        </form>
        <?php
        if(isset($_POST['submit']))
        {
            $file = $_FILES['file']['tmp_name'];

            $fetch = $con->query("SELECT username FROM tablename"); //tablename in which you import the data
            $i=0;
            while($fetch_array = mysqli_fetch_array($fetch)){  //checks if the record already exist or not. if exist it skips

                $variablename[$i++]=$fetch_array["columnname"];  // columnname in column which is unique

            }

            $handle = fopen($file, 'r');
            $c = 0;
            while(($filesop = fgetcsv($handle, 1000, ',')) !== false)
            {

               


                if($filesop[0]=="columnname in csv" || $filesop[0]=="" || in_array(fieldname,array of table))
                    continue;
///////////////////////////////////// just for reference
                $name = $filesop[1];
                $username = $filesop[3];
                $email = $filesop[2];
                $password = $filesop[4];
                $password = md5($password);
                $created_on = $filesop[0];
/////////////////////////////////////// values as above variables
                $sql = $con->query("INSERT INTO table name (columnnames) VALUES ('"values");
                $c = $c + 1;
            }

            if($c){
                echo "You database has imported successfully. You have inserted ". $c ." records";
            }else{
                echo "no record inserted.";
            }

        }
        ?>
    </div>
</body>
</html>




No comments :

Post a Comment

Find age thought php code

No comments


This is one of the simple task in php.

<?php





$birthdate='1989-07-07';
echo date_diff(date_create($birthdate), date_create('today'))->y;

?>

No comments :

Post a Comment

Joomla make custom Module for LOGIN in POPUP window

No comments
//Just copy and paste this code in default.php of your module.

<?php

defined('_JEXEC') or die;
JHTML::_('behavior.modal');


$user = JFactory::getUser(); //get user credentials

?>

<div class="btl-panel">
   <?php if($user->guest){?>
          <a class="modal login-popup" href="index.php?option=com_users&view=login&tmpl=component" rel="{ size: {x: 480, y: 340}}" >Login</a>
    <?php }else{ ?>
         <a  class="" href="index.php?option=com_users&task=user.logout&<?php echo JSession::getFormToken();?>=1">Logout</a>
    <?php } ?>
</div>

No comments :

Post a Comment

PHP CURL coding

No comments

 <?php
$ch= curl_init();



$url ="www.domain.com";
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,5);


$curl_result=curl_exec($ch);
curl_close($ch);
$curl_result=str_replace("<","<",$curl_result);
$curl_result=str_replace(">",">",$curl_result);
echo $curl_result;
?>

No comments :

Post a Comment

Stuck Installing Joomla On Windows 8 and Windows 10

No comments
SOLUTION ONE:
Change max_execute_time in php.ini to a value like 200 when done or when in production change it back to 60 or less.

SOLUTION TWO:
CHANGE MYSQL ENGINE REFERENCE
in php.ini file turn
Output_Buffering=Off Display_Errors=Off and in wamp\www\Your joomla folder\installation\sql\mysql\Joomla.sql replaced all the occurence of "ENGINE=InnoDB" with "ENGINE=MyIsam"

SOLUTION THREE:
If changing max_execute_time or replacing InnoDB didn't work for you, try to install it in different browser like IE or Opera if you've run it in Chrome & Firefox already.

No comments :

Post a Comment