Elasticsearch search result problem ( Urgently)

2015-02-11 Thread Veli Can TEFON
Hello,

I add data add Elasticsearch this code :

$data = array(name=HelperMC::strToUtf8(trim($name)),
urlname=HelperURL::strToURL(trim($name)),
price=number_format(HelperParser::clearTextFromPrice($price), 
2, ',', '.'),
price_for_filter=HelperParser::clearTextFromPrice($price),
image=$imgname,
description=HelperMC::strToUtf8($description),
keywords=HelperMC::strToUtf8($keywords),
url=$k['url'],
sitemap_id=intval($sitemapId),
shop_id=$shop['shop_id'],
logo=$shop['logo'],
key=$hashKey,
type=intval(1),
shop_rating_count=intval($shop['rating_count']),
shop_rating_point=intval($shop['rating_point']),
created_at=date(Y-m-d H:i:s),
updated_at=date(Y-m-d H:i:s));
   
//create elasticsearch index
HelperES::insertEntry(json_encode($data),$hashKey); 



My insertEntry Function:

private static $elasticBase = http://localhost:9200/shopping/items;;

public static function insertEntry($data_string,$id = false){
if($id)
$url = self::$elasticBase./.$id;
else
$url = self::$elasticBase;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL , $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, POST);  
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
@$result = curl_exec($ch);
curl_close($ch);

return $result;
}



and my search Function :

public static function search($keyword, $defaultOperator = OR ,$start 
= 0, $size = 25, $from = 0, $to = 1, $shopsArr = array(),$orderBy = 
price, $order = asc){
$searchUrl = self::$elasticBase./_search;

if(count($shopsArr)  0){
$query = '{
from : '.$start.', size : '.$size.',
query : {
filtered : {
 query: {
query_string: { query: '.$keyword.
',
fields: [name,urlname],
default_operator: '.$defaultOperator.
'
}
  },
filter : {
 bool : {
must : {
terms : { sitemap_id : '
.json_encode($shopsArr).' }
},
must : {
range : {

price_for_filter : {
from : '.
$from.',
to  : '.
$to.'
}
  }
}
}
}
}
},
sort : [
  {'.$orderBy.' : {order : '.$order
.', mode : avg}}
 ]
}';
}else{
$query = '{
from : '.$start.', size : '.$size.',
query : {
filtered : {
 query: {
query_string: { 
query: '.$keyword.',
fields: [name,urlname],
default_operator: '.$defaultOperator.
'
}
  },
filter : {
range : {
price_for_filter : {
from : '.$from.',
to  : '.$to.'
}
}
}
}
},
sort : [
 {'.$orderBy.' : {order : '.$order.', 
mode : avg}}
 ]
}';
}


echo $query;


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL , $searchUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, POST);  
curl_setopt($ch, CURLOPT_POSTFIELDS, $query); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 

Re: Elasticsearch search result problem

2015-02-11 Thread Veli Can TEFON
i think problem price_for_filter but working this - http://goo.gl/AuxCrR


11 Şubat 2015 Çarşamba 06:09:13 UTC+2 tarihinde Veli Can TEFON yazdı:

 Hello,

 I add data add Elasticsearch this code :

 $data = array(name=HelperMC::strToUtf8(trim($name)),
 urlname=HelperURL::strToURL(trim($name)),
 price=number_format(HelperParser::clearTextFromPrice($price
 ), 2, ',', '.'),
 price_for_filter=HelperParser::clearTextFromPrice($price),
 image=$imgname,
 description=HelperMC::strToUtf8($description),
 keywords=HelperMC::strToUtf8($keywords),
 url=$k['url'],
 sitemap_id=intval($sitemapId),
 shop_id=$shop['shop_id'],
 logo=$shop['logo'],
 key=$hashKey,
 type=intval(1),
 shop_rating_count=intval($shop['rating_count']),
 shop_rating_point=intval($shop['rating_point']),
 created_at=date(Y-m-d H:i:s),
 updated_at=date(Y-m-d H:i:s));

 //create elasticsearch index
 HelperES::insertEntry(json_encode($data),$hashKey); 



 My insertEntry Function:

 private static $elasticBase = http://localhost:9200/shopping/items;;

 public static function insertEntry($data_string,$id = false){
 if($id)
 $url = self::$elasticBase./.$id;
 else
 $url = self::$elasticBase;

 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL , $url);
 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, POST);  
 curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); 
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
 @$result = curl_exec($ch);
 curl_close($ch);

 return $result;
 }



 and my search Function :

 public static function search($keyword, $defaultOperator = OR ,$start 
 = 0, $size = 25, $from = 0, $to = 1, $shopsArr = array(),$orderBy = 
 price, $order = asc){
 $searchUrl = self::$elasticBase./_search;

 if(count($shopsArr)  0){
 $query = '{
 from : '.$start.', size : '.$size.',
 query : {
 filtered : {
  query: {
 query_string: { query: '.$keyword
 .',
 fields: [name,urlname],
 default_operator: '.
 $defaultOperator.'
 }
   },
 filter : {
  bool : {
 must : {
 terms : { sitemap_id : 
 '.json_encode($shopsArr).' }
 },
 must : {
 range : {
 
 price_for_filter : {
 from : '
 .$from.',
 to  : '
 .$to.'
 }
   }
 }
 }
 }
 }
 },
 sort : [
   {'.$orderBy.' : {order : '.
 $order.', mode : avg}}
  ]
 }';
 }else{
 $query = '{
 from : '.$start.', size : '.$size.',
 query : {
 filtered : {
  query: {
 query_string: { 
 query: '.$keyword.',
 fields: [name,urlname],
 default_operator: '.
 $defaultOperator.'
 }
   },
 filter : {
 range : {
 price_for_filter : {
 from : '.$from.',
 to  : '.$to.'
 }
 }
 }
 }
 },
 sort : [
  {'.$orderBy.' : {order : '.$order.', 
 mode : avg

Elasticsearch search result problem

2015-02-10 Thread Veli Can TEFON
Hello,

I add data add Elasticsearch this code :

$data = array(name=HelperMC::strToUtf8(trim($name)),
urlname=HelperURL::strToURL(trim($name)),
price=number_format(HelperParser::clearTextFromPrice($price), 
2, ',', '.'),
price_for_filter=HelperParser::clearTextFromPrice($price),
image=$imgname,
description=HelperMC::strToUtf8($description),
keywords=HelperMC::strToUtf8($keywords),
url=$k['url'],
sitemap_id=intval($sitemapId),
shop_id=$shop['shop_id'],
logo=$shop['logo'],
key=$hashKey,
type=intval(1),
shop_rating_count=intval($shop['rating_count']),
shop_rating_point=intval($shop['rating_point']),
created_at=date(Y-m-d H:i:s),
updated_at=date(Y-m-d H:i:s));
   
//create elasticsearch index
HelperES::insertEntry(json_encode($data),$hashKey); 



My insertEntry Function:

private static $elasticBase = http://localhost:9200/shopping/items;;

public static function insertEntry($data_string,$id = false){
if($id)
$url = self::$elasticBase./.$id;
else
$url = self::$elasticBase;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL , $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, POST);  
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
@$result = curl_exec($ch);
curl_close($ch);

return $result;
}



and my search Function :

public static function search($keyword, $defaultOperator = OR ,$start 
= 0, $size = 25, $from = 0, $to = 1, $shopsArr = array(),$orderBy = 
price, $order = asc){
$searchUrl = self::$elasticBase./_search;

if(count($shopsArr)  0){
$query = '{
from : '.$start.', size : '.$size.',
query : {
filtered : {
 query: {
query_string: { query: '.$keyword.
',
fields: [name,urlname],
default_operator: '.$defaultOperator.
'
}
  },
filter : {
 bool : {
must : {
terms : { sitemap_id : '
.json_encode($shopsArr).' }
},
must : {
range : {

price_for_filter : {
from : '.
$from.',
to  : '.
$to.'
}
  }
}
}
}
}
},
sort : [
  {'.$orderBy.' : {order : '.$order
.', mode : avg}}
 ]
}';
}else{
$query = '{
from : '.$start.', size : '.$size.',
query : {
filtered : {
 query: {
query_string: { 
query: '.$keyword.',
fields: [name,urlname],
default_operator: '.$defaultOperator.
'
}
  },
filter : {
range : {
price_for_filter : {
from : '.$from.',
to  : '.$to.'
}
}
}
}
},
sort : [
 {'.$orderBy.' : {order : '.$order.', 
mode : avg}}
 ]
}';
}


echo $query;


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL , $searchUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, POST);  
curl_setopt($ch, CURLOPT_POSTFIELDS, $query); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,