I'm using sphinx php api to sort search results. I want to give more weight to title and less to content, I've tried setting setFieldWeights
$sp->setFieldWeights(array('title'=>10,'full_story'=>1)); but it's not working at all. not matter how i change the weight, results stays the same.
print_r with "test" as a search word and setFieldWeights(array('title'=>10,'full_story'=>1));
Array ( [error] => [warning] => [status] => 0 [fields] => Array ( [0] => title [1] => full_story [2] => category ) [attrs] => Array ( [date] => 2 ) [matches] => Array ( [0] => Array ( [id] => 1933 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [1] => Array ( [id] => 2824 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [2] => Array ( [id] => 2860 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [3] => Array ( [id] => 2865 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [4] => Array ( [id] => 5720 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [5] => Array ( [id] => 6963 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [6] => Array ( [id] => 8190 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [7] => Array ( [id] => 8591 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [8] => Array ( [id] => 10114 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [9] => Array ( [id] => 10157 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [10] => Array ( [id] => 11162 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [11] => Array ( [id] => 11659 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [12] => Array ( [id] => 13219 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [13] => Array ( [id] => 13220 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [14] => Array ( [id] => 13565 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [15] => Array ( [id] => 13576 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [16] => Array ( [id] => 14801 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [17] => Array ( [id] => 14857 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [18] => Array ( [id] => 17311 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [19] => Array ( [id] => 17511 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [20] => Array ( [id] => 18131 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [21] => Array ( [id] => 19171 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [22] => Array ( [id] => 21134 [weight] => 10 [attrs] => Array ( [date] => 2012 ) ) [23] => Array ( [id] => 23007 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [24] => Array ( [id] => 23230 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [25] => Array ( [id] => 23460 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [26] => Array ( [id] => 23473 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [27] => Array ( [id] => 25609 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [28] => Array ( [id] => 28093 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [29] => Array ( [id] => 28175 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [30] => Array ( [id] => 30364 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [31] => Array ( [id] => 30506 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [32] => Array ( [id] => 31439 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [33] => Array ( [id] => 31668 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [34] => Array ( [id] => 32017 [weight] => 10 [attrs] => Array ( [date] => 2013 ) ) [35] => Array ( [id] => 1432 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [36] => Array ( [id] => 5362 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [37] => Array ( [id] => 9175 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [38] => Array ( [id] => 13817 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [39] => Array ( [id] => 14132 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [40] => Array ( [id] => 14658 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [41] => Array ( [id] => 15792 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [42] => Array ( [id] => 16615 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [43] => Array ( [id] => 18177 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [44] => Array ( [id] => 18581 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [45] => Array ( [id] => 18618 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [46] => Array ( [id] => 18665 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [47] => Array ( [id] => 18718 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [48] => Array ( [id] => 19096 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [49] => Array ( [id] => 19128 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [50] => Array ( [id] => 19464 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [51] => Array ( [id] => 20014 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [52] => Array ( [id] => 20144 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [53] => Array ( [id] => 20306 [weight] => 1 [attrs] => Array ( [date] => 2012 ) ) [54] => Array ( [id] => 22604 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [55] => Array ( [id] => 23870 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [56] => Array ( [id] => 23994 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [57] => Array ( [id] => 24507 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [58] => Array ( [id] => 24617 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [59] => Array ( [id] => 25043 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [60] => Array ( [id] => 25350 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [61] => Array ( [id] => 26063 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [62] => Array ( [id] => 26614 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [63] => Array ( [id] => 26819 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [64] => Array ( [id] => 28292 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [65] => Array ( [id] => 29155 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [66] => Array ( [id] => 30854 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [67] => Array ( [id] => 31566 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [68] => Array ( [id] => 31704 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) [69] => Array ( [id] => 32092 [weight] => 1 [attrs] => Array ( [date] => 2013 ) ) ) [total] => 70 [total_found] => 70 [time] => 0,017 [words] => Array ( [*test*] => Array ( [docs] => 70 [hits] => 70 ) ) )
print_r with "test" as a search word and setFieldWeights(array('title'=>10000,'full_story'=>1));
Array ( [error] => [warning] => [status] => 0 [fields] => Array ( [0] => title [1] => full_story [2] => category [3] => date ) [attrs] => Array ( ) [matches] => Array ( [0] => Array ( [id] => 1933 [weight] => 10000 [attrs] => Array ( ) ) [1] => Array ( [id] => 2824 [weight] => 10000 [attrs] => Array ( ) ) [2] => Array ( [id] => 2860 [weight] => 10000 [attrs] => Array ( ) ) [3] => Array ( [id] => 2865 [weight] => 10000 [attrs] => Array ( ) ) [4] => Array ( [id] => 5720 [weight] => 10000 [attrs] => Array ( ) ) [5] => Array ( [id] => 6963 [weight] => 10000 [attrs] => Array ( ) ) [6] => Array ( [id] => 8190 [weight] => 10000 [attrs] => Array ( ) ) [7] => Array ( [id] => 8591 [weight] => 10000 [attrs] => Array ( ) ) [8] => Array ( [id] => 10114 [weight] => 10000 [attrs] => Array ( ) ) [9] => Array ( [id] => 10157 [weight] => 10000 [attrs] => Array ( ) ) [10] => Array ( [id] => 11162 [weight] => 10000 [attrs] => Array ( ) ) [11] => Array ( [id] => 11659 [weight] => 10000 [attrs] => Array ( ) ) [12] => Array ( [id] => 13219 [weight] => 10000 [attrs] => Array ( ) ) [13] => Array ( [id] => 13220 [weight] => 10000 [attrs] => Array ( ) ) [14] => Array ( [id] => 13565 [weight] => 10000 [attrs] => Array ( ) ) [15] => Array ( [id] => 13576 [weight] => 10000 [attrs] => Array ( ) ) [16] => Array ( [id] => 14801 [weight] => 10000 [attrs] => Array ( ) ) [17] => Array ( [id] => 14857 [weight] => 10000 [attrs] => Array ( ) ) [18] => Array ( [id] => 17311 [weight] => 10000 [attrs] => Array ( ) ) [19] => Array ( [id] => 17511 [weight] => 10000 [attrs] => Array ( ) ) [20] => Array ( [id] => 18131 [weight] => 10000 [attrs] => Array ( ) ) [21] => Array ( [id] => 19171 [weight] => 10000 [attrs] => Array ( ) ) [22] => Array ( [id] => 21134 [weight] => 10000 [attrs] => Array ( ) ) [23] => Array ( [id] => 23007 [weight] => 10000 [attrs] => Array ( ) ) [24] => Array ( [id] => 23230 [weight] => 10000 [attrs] => Array ( ) ) [25] => Array ( [id] => 23460 [weight] => 10000 [attrs] => Array ( ) ) [26] => Array ( [id] => 23473 [weight] => 10000 [attrs] => Array ( ) ) [27] => Array ( [id] => 25609 [weight] => 10000 [attrs] => Array ( ) ) [28] => Array ( [id] => 28093 [weight] => 10000 [attrs] => Array ( ) ) [29] => Array ( [id] => 28175 [weight] => 10000 [attrs] => Array ( ) ) [30] => Array ( [id] => 30364 [weight] => 10000 [attrs] => Array ( ) ) [31] => Array ( [id] => 30506 [weight] => 10000 [attrs] => Array ( ) ) [32] => Array ( [id] => 31439 [weight] => 10000 [attrs] => Array ( ) ) [33] => Array ( [id] => 31668 [weight] => 10000 [attrs] => Array ( ) ) [34] => Array ( [id] => 32017 [weight] => 10000 [attrs] => Array ( ) ) [35] => Array ( [id] => 1432 [weight] => 1 [attrs] => Array ( ) ) [36] => Array ( [id] => 5362 [weight] => 1 [attrs] => Array ( ) ) [37] => Array ( [id] => 9175 [weight] => 1 [attrs] => Array ( ) ) [38] => Array ( [id] => 13817 [weight] => 1 [attrs] => Array ( ) ) [39] => Array ( [id] => 14132 [weight] => 1 [attrs] => Array ( ) ) [40] => Array ( [id] => 14658 [weight] => 1 [attrs] => Array ( ) ) [41] => Array ( [id] => 15792 [weight] => 1 [attrs] => Array ( ) ) [42] => Array ( [id] => 16615 [weight] => 1 [attrs] => Array ( ) ) [43] => Array ( [id] => 18177 [weight] => 1 [attrs] => Array ( ) ) [44] => Array ( [id] => 18581 [weight] => 1 [attrs] => Array ( ) ) [45] => Array ( [id] => 18618 [weight] => 1 [attrs] => Array ( ) ) [46] => Array ( [id] => 18665 [weight] => 1 [attrs] => Array ( ) ) [47] => Array ( [id] => 18718 [weight] => 1 [attrs] => Array ( ) ) [48] => Array ( [id] => 19096 [weight] => 1 [attrs] => Array ( ) ) [49] => Array ( [id] => 19128 [weight] => 1 [attrs] => Array ( ) ) [50] => Array ( [id] => 19464 [weight] => 1 [attrs] => Array ( ) ) [51] => Array ( [id] => 20014 [weight] => 1 [attrs] => Array ( ) ) [52] => Array ( [id] => 20144 [weight] => 1 [attrs] => Array ( ) ) [53] => Array ( [id] => 20306 [weight] => 1 [attrs] => Array ( ) ) [54] => Array ( [id] => 22604 [weight] => 1 [attrs] => Array ( ) ) [55] => Array ( [id] => 23870 [weight] => 1 [attrs] => Array ( ) ) [56] => Array ( [id] => 23994 [weight] => 1 [attrs] => Array ( ) ) [57] => Array ( [id] => 24507 [weight] => 1 [attrs] => Array ( ) ) [58] => Array ( [id] => 24617 [weight] => 1 [attrs] => Array ( ) ) [59] => Array ( [id] => 25043 [weight] => 1 [attrs] => Array ( ) ) [60] => Array ( [id] => 25350 [weight] => 1 [attrs] => Array ( ) ) [61] => Array ( [id] => 26063 [weight] => 1 [attrs] => Array ( ) ) [62] => Array ( [id] => 26614 [weight] => 1 [attrs] => Array ( ) ) [63] => Array ( [id] => 26819 [weight] => 1 [attrs] => Array ( ) ) [64] => Array ( [id] => 28292 [weight] => 1 [attrs] => Array ( ) ) [65] => Array ( [id] => 29155 [weight] => 1 [attrs] => Array ( ) ) [66] => Array ( [id] => 30854 [weight] => 1 [attrs] => Array ( ) ) [67] => Array ( [id] => 31566 [weight] => 1 [attrs] => Array ( ) ) [68] => Array ( [id] => 31704 [weight] => 1 [attrs] => Array ( ) ) [69] => Array ( [id] => 32092 [weight] => 1 [attrs] => Array ( ) ) ) [total] => 70 [total_found] => 70 [time] => 0,000 [words] => Array ( [*test*] => Array ( [docs] => 70 [hits] => 70 ) ) )
print_r with "test" as a search word without setFieldWeights
Array ( [error] => [warning] => [status] => 0 [fields] => Array ( [0] => title [1] => full_story [2] => category [3] => date ) [attrs] => Array ( ) [matches] => Array ( [0] => Array ( [id] => 1432 [weight] => 1 [attrs] => Array ( ) ) [1] => Array ( [id] => 1933 [weight] => 1 [attrs] => Array ( ) ) [2] => Array ( [id] => 2824 [weight] => 1 [attrs] => Array ( ) ) [3] => Array ( [id] => 2860 [weight] => 1 [attrs] => Array ( ) ) [4] => Array ( [id] => 2865 [weight] => 1 [attrs] => Array ( ) ) [5] => Array ( [id] => 5362 [weight] => 1 [attrs] => Array ( ) ) [6] => Array ( [id] => 5720 [weight] => 1 [attrs] => Array ( ) ) [7] => Array ( [id] => 6963 [weight] => 1 [attrs] => Array ( ) ) [8] => Array ( [id] => 8190 [weight] => 1 [attrs] => Array ( ) ) [9] => Array ( [id] => 8591 [weight] => 1 [attrs] => Array ( ) ) [10] => Array ( [id] => 9175 [weight] => 1 [attrs] => Array ( ) ) [11] => Array ( [id] => 10114 [weight] => 1 [attrs] => Array ( ) ) [12] => Array ( [id] => 10157 [weight] => 1 [attrs] => Array ( ) ) [13] => Array ( [id] => 11162 [weight] => 1 [attrs] => Array ( ) ) [14] => Array ( [id] => 11659 [weight] => 1 [attrs] => Array ( ) ) [15] => Array ( [id] => 13219 [weight] => 1 [attrs] => Array ( ) ) [16] => Array ( [id] => 13220 [weight] => 1 [attrs] => Array ( ) ) [17] => Array ( [id] => 13565 [weight] => 1 [attrs] => Array ( ) ) [18] => Array ( [id] => 13576 [weight] => 1 [attrs] => Array ( ) ) [19] => Array ( [id] => 13817 [weight] => 1 [attrs] => Array ( ) ) [20] => Array ( [id] => 14132 [weight] => 1 [attrs] => Array ( ) ) [21] => Array ( [id] => 14658 [weight] => 1 [attrs] => Array ( ) ) [22] => Array ( [id] => 14801 [weight] => 1 [attrs] => Array ( ) ) [23] => Array ( [id] => 14857 [weight] => 1 [attrs] => Array ( ) ) [24] => Array ( [id] => 15792 [weight] => 1 [attrs] => Array ( ) ) [25] => Array ( [id] => 16615 [weight] => 1 [attrs] => Array ( ) ) [26] => Array ( [id] => 17311 [weight] => 1 [attrs] => Array ( ) ) [27] => Array ( [id] => 17511 [weight] => 1 [attrs] => Array ( ) ) [28] => Array ( [id] => 18131 [weight] => 1 [attrs] => Array ( ) ) [29] => Array ( [id] => 18177 [weight] => 1 [attrs] => Array ( ) ) [30] => Array ( [id] => 18581 [weight] => 1 [attrs] => Array ( ) ) [31] => Array ( [id] => 18618 [weight] => 1 [attrs] => Array ( ) ) [32] => Array ( [id] => 18665 [weight] => 1 [attrs] => Array ( ) ) [33] => Array ( [id] => 18718 [weight] => 1 [attrs] => Array ( ) ) [34] => Array ( [id] => 19096 [weight] => 1 [attrs] => Array ( ) ) [35] => Array ( [id] => 19128 [weight] => 1 [attrs] => Array ( ) ) [36] => Array ( [id] => 19171 [weight] => 1 [attrs] => Array ( ) ) [37] => Array ( [id] => 19464 [weight] => 1 [attrs] => Array ( ) ) [38] => Array ( [id] => 20014 [weight] => 1 [attrs] => Array ( ) ) [39] => Array ( [id] => 20144 [weight] => 1 [attrs] => Array ( ) ) [40] => Array ( [id] => 20306 [weight] => 1 [attrs] => Array ( ) ) [41] => Array ( [id] => 21134 [weight] => 1 [attrs] => Array ( ) ) [42] => Array ( [id] => 22604 [weight] => 1 [attrs] => Array ( ) ) [43] => Array ( [id] => 23007 [weight] => 1 [attrs] => Array ( ) ) [44] => Array ( [id] => 23230 [weight] => 1 [attrs] => Array ( ) ) [45] => Array ( [id] => 23460 [weight] => 1 [attrs] => Array ( ) ) [46] => Array ( [id] => 23473 [weight] => 1 [attrs] => Array ( ) ) [47] => Array ( [id] => 23870 [weight] => 1 [attrs] => Array ( ) ) [48] => Array ( [id] => 23994 [weight] => 1 [attrs] => Array ( ) ) [49] => Array ( [id] => 24507 [weight] => 1 [attrs] => Array ( ) ) [50] => Array ( [id] => 24617 [weight] => 1 [attrs] => Array ( ) ) [51] => Array ( [id] => 25043 [weight] => 1 [attrs] => Array ( ) ) [52] => Array ( [id] => 25350 [weight] => 1 [attrs] => Array ( ) ) [53] => Array ( [id] => 25609 [weight] => 1 [attrs] => Array ( ) ) [54] => Array ( [id] => 26063 [weight] => 1 [attrs] => Array ( ) ) [55] => Array ( [id] => 26614 [weight] => 1 [attrs] => Array ( ) ) [56] => Array ( [id] => 26819 [weight] => 1 [attrs] => Array ( ) ) [57] => Array ( [id] => 28093 [weight] => 1 [attrs] => Array ( ) ) [58] => Array ( [id] => 28175 [weight] => 1 [attrs] => Array ( ) ) [59] => Array ( [id] => 28292 [weight] => 1 [attrs] => Array ( ) ) [60] => Array ( [id] => 29155 [weight] => 1 [attrs] => Array ( ) ) [61] => Array ( [id] => 30364 [weight] => 1 [attrs] => Array ( ) ) [62] => Array ( [id] => 30506 [weight] => 1 [attrs] => Array ( ) ) [63] => Array ( [id] => 30854 [weight] => 1 [attrs] => Array ( ) ) [64] => Array ( [id] => 31439 [weight] => 1 [attrs] => Array ( ) ) [65] => Array ( [id] => 31566 [weight] => 1 [attrs] => Array ( ) ) [66] => Array ( [id] => 31668 [weight] => 1 [attrs] => Array ( ) ) [67] => Array ( [id] => 31704 [weight] => 1 [attrs] => Array ( ) ) [68] => Array ( [id] => 32017 [weight] => 1 [attrs] => Array ( ) ) [69] => Array ( [id] => 32092 [weight] => 1 [attrs] => Array ( ) ) ) [total] => 70 [total_found] => 70 [time] => 0,000 [words] => Array ( [*test*] => Array ( [docs] => 70 [hits] => 70 ) ) )
sphinx php api
// Include the sphinx API class
require(ENGINE_DIR . "/modules/sphinxapi.php");
$sp = new SphinxClient();
$sp->setFieldWeights(array('title'=>10,'full_story'=>1));
$sp->SetMatchMode(SPH_MATCH_all);
$sp->SetArrayResult(true);
$sp->SetLimits(0,$count_result = ($config['search_number'] * 5));
$query = explode(" ",$story);
$query = implode(array_map(function($item) { return ' *' . $item . '* '; }, $query));
$results = $sp->Query($query, $config['sphinx_index']);
print_r($results);
$count_result = $results['total_found'];
$result_count = $count_result;
than i'm performing a select in on ids
$sql_request = "SELECT * from post WHERE id IN {$rIds} LIMIT $search_start,{$config['search_number']}";
sphinx conf
type = mysql
sql_host = localhost
sql_user = user
sql_pass = pass
sql_db = user
sql_port = 3306 # optional, default is 3306
sql_query_pre = REPLACE INTO sph_counter SELECT 1, MAX(id) FROM post
sql_query_pre = SET NAMES utf8
sql_query_pre = SET CHARACTER SET utf8
sql_query_pre = SET SESSION query_cache_type=OFF
sql_query = SELECT id, title, full_story, category, DATE FROM post WHERE approve='1' AND id <=( SELECT max_doc_id FROM sph_counter WHERE counter_id=1 )
#sql_attr_timestamp = DATE
sql_ranged_throttle = 0
index
index online_test
{
source = online_test_posts
path = /var/lib/sphinx/online_test
docinfo = extern
charset_type = utf-8
morphology = stem_enru
min_word_len = 1
min_prefix_len = 0
min_infix_len = 1
mlock = 0
charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F
enable_star = 1
rt_mem_limit = 512M
}
my indication is a post with a title "Test Your Brain" with an id '2865' it's should be at least second. instead i'm getting post with a title "Coming & Going" with full_story content test, id post - 1432
by the way, if I'm running search from command line the results are much more accurate.
search test
index 'online_test': query 'test ': returned 7 matches of 7 total in 0.008 sec
displaying matches:
1. document=2865, weight=1684
2. document=5362, weight=1684
3. document=8190, weight=1684
4. document=23460, weight=1684
5. document=25609, weight=1684
6. document=31704, weight=1684
7. document=32092, weight=1684
Well you've proved yourself, that setFieldWeights is working :)
When no weights: [4] => Array ( [id] => 2865 [weight] => 1 [attrs] => Array ( )
When 10: [4] => Array ( [id] => 5720 [weight] => 10 [attrs] => Array ( [date] => 2013 )
When 10000: [4] => Array ( [id] => 5720 [weight] => 10000 [attrs] => Array ( )
And when have weights set, you have documents with different weights:
[34] => Array ( [id] => 32017 [weight] => 10 [attrs] => Array ( [date] => 2013 )
[35] => Array ( [id] => 1432 [weight] => 1 [attrs] => Array ( [date] => 2012 )
... so some results (persuambly with a match on the title) have a higher wieght, and promoted above the description matches.
The fact that some tests have the date atttribute, and some dont, is just because you run the tests at different times? (so not a real problem, just an artifact of your testing?)
What I wonder, if you realise, you are just doing:
$sql_request = "SELECT * from post WHERE id IN {$rIds} LIMIT $search_start,{$config['search_number']}";
which will just return the results in arbitary order (what ever mysql deems fit).
Maybe you are looking at the results of the mysql query directly, and not realising you need to sort the results yourself, so they match the order returned from sphinx.
And you have odd LIMIT. The SQL query shouldnt have a limit, because paging is done in sphinx NOT in mysql.
Suggest
$sql_request = "SELECT * from post WHERE id IN {$rIds} ORDER BY FIELD(id,{$rIds})";
So that mysql will return you the results sorted correctly.
From: http://sphinxsearch.com/info/faq/
Related
I have an input category array with childs as follows
I want to convert it using a recursive function to another array like
OUTPUT NEEDED
['1'=>'fashion', '10' => 'fashion > women','23'=> 'fashion > women > clothing','29'=> 'fashion > women > clothing > dresses' ... and so on ]
My purpose is to use output array to populate select box options to adda category.
INPUT ARRAY
Array
(
[1] => Array
(
[id] => 1
[name] => fashion
[parent_id] => 0
[childs] => Array
(
[10] => Array
(
[id] => 10
[name] => women
[parent_id] => 1
[childs] => Array
(
[23] => Array
(
[id] => 23
[name] => clothing
[parent_id] => 10
[childs] => Array
(
[29] => Array
(
[id] => 29
[name] => dresses
[parent_id] => 23
[childs] => Array
(
)
)
[30] => Array
(
[id] => 30
[name] => jumpsuits
[parent_id] => 23
[childs] => Array
(
)
)
)
)
[24] => Array
(
[id] => 24
[name] => bags & accessories
[parent_id] => 10
[childs] => Array
(
)
)
[25] => Array
(
[id] => 25
[name] => shoes
[parent_id] => 10
[childs] => Array
(
)
)
[26] => Array
(
[id] => 26
[name] => watches
[parent_id] => 10
[childs] => Array
(
)
)
[27] => Array
(
[id] => 27
[name] => jewelery
[parent_id] => 10
[childs] => Array
(
)
)
[28] => Array
(
[id] => 28
[name] => eye-wear
[parent_id] => 10
[childs] => Array
(
)
)
)
)
[11] => Array
(
[id] => 11
[name] => men
[parent_id] => 1
[childs] => Array
(
)
)
[12] => Array
(
[id] => 12
[name] => kids
[parent_id] => 1
[childs] => Array
(
)
)
[13] => Array
(
[id] => 13
[name] => sports
[parent_id] => 1
[childs] => Array
(
)
)
[14] => Array
(
[id] => 14
[name] => bags
[parent_id] => 1
[childs] => Array
(
)
)
[15] => Array
(
[id] => 15
[name] => eyewear
[parent_id] => 1
[childs] => Array
(
)
)
[16] => Array
(
[id] => 16
[name] => watches & jewelery
[parent_id] => 1
[childs] => Array
(
)
)
)
)
[2] => Array
(
[id] => 2
[name] => supermarket
[parent_id] => 0
[childs] => Array
(
[17] => Array
(
[id] => 17
[name] => food & beverages
[parent_id] => 2
[childs] => Array
(
[31] => Array
(
[id] => 31
[name] => breakfast
[parent_id] => 17
[childs] => Array
(
)
)
[32] => Array
(
[id] => 32
[name] => snacks
[parent_id] => 17
[childs] => Array
(
)
)
)
)
[18] => Array
(
[id] => 18
[name] => dairy products
[parent_id] => 2
[childs] => Array
(
)
)
[19] => Array
(
[id] => 19
[name] => beauty
[parent_id] => 2
[childs] => Array
(
)
)
[20] => Array
(
[id] => 20
[name] => homecare
[parent_id] => 2
[childs] => Array
(
)
)
[21] => Array
(
[id] => 21
[name] => baby world
[parent_id] => 2
[childs] => Array
(
)
)
[22] => Array
(
[id] => 22
[name] => pet world
[parent_id] => 2
[childs] => Array
(
)
)
)
)
[3] => Array
(
[id] => 3
[name] => electronics
[parent_id] => 0
[childs] => Array
(
[33] => Array
(
[id] => 33
[name] => laptops
[parent_id] => 3
[childs] => Array
(
)
)
[34] => Array
(
[id] => 34
[name] => television
[parent_id] => 3
[childs] => Array
(
)
)
)
)
[4] => Array
(
[id] => 4
[name] => mobiles & tablets
[parent_id] => 0
[childs] => Array
(
[35] => Array
(
[id] => 35
[name] => mobiles
[parent_id] => 4
[childs] => Array
(
)
)
[36] => Array
(
[id] => 36
[name] => tablets
[parent_id] => 4
[childs] => Array
(
)
)
)
)
[5] => Array
(
[id] => 5
[name] => baby & toys
[parent_id] => 0
[childs] => Array
(
)
)
[6] => Array
(
[id] => 6
[name] => home
[parent_id] => 0
[childs] => Array
(
)
)
[7] => Array
(
[id] => 7
[name] => perfumes & beauty
[parent_id] => 0
[childs] => Array
(
)
)
[8] => Array
(
[id] => 8
[name] => sports & fitness
[parent_id] => 0
[childs] => Array
(
)
)
[9] => Array
(
[id] => 9
[name] => automotive
[parent_id] => 0
[childs] => Array
(
)
)
)
I need an output array with key,the category id
You can create array by this way:
$array = array(
'category_1' => 'value',
'category_2' => array(
'subcategory_1' => 'value',
'subcategory_2' => 'value',
),
);
I just started using moltin and learn to developing it.
In the getting started there is code that to show product
<?php
$product = \Product::Find(['slug' => 'baju']);
?>
documentation link https://moltin.com/getting-started/php
and the result is when I print array
<?php
print_r($product);
?>
It shows like this
Array ( [status] => 1 [result] => Array ( [0] => Array ( [id] => 1207658536885027482 [order] => [created_at] => 2016-03-17 03:08:58 [updated_at] => 2016-03-17 03:08:58 [sku] => baju-1 [title] => baju [slug] => baju [sale_price] => 0 [status] => Array ( [value] => Live [data] => Array ( [key] => 1 [value] => Live ) ) [category] => Array ( [value] => Uncategorized [data] => Array ( [1134518259857490806] => Array ( [id] => 1134518259857490806 [order] => [created_at] => 2015-12-07 05:12:15 [updated_at] => 2015-12-07 05:12:15 [parent] => [slug] => uncategorized [status] => Array ( [value] => Live [data] => Array ( [key] => 1 [value] => Live ) ) [title] => Uncategorized [description] => Products that do not fit into another category ) ) ) [stock_level] => 10 [stock_status] => Array ( [value] => In Stock [data] => Array ( [key] => 1 [value] => In Stock ) ) [description] => baju [requires_shipping] => Array ( [value] => Yes [data] => Array ( [key] => 1 [value] => Yes ) ) [weight] => 0 [height] => 0 [width] => 0 [depth] => 0 [catalog_only] => Array ( [value] => No [data] => Array ( [key] => 0 [value] => No ) ) [tax_band] => Array ( [value] => Default [data] => Array ( [id] => 1134518260142703561 [title] => Default [description] => [rate] => 20 [created_at] => [updated_at] => ) ) [collection] => [brand] => [price] => Array ( [value] => £1.20 [data] => Array ( [formatted] => Array ( [with_tax] => £1.20 [without_tax] => £1.00 [tax] => £0.20 ) [rounded] => Array ( [with_tax] => 1.2 [without_tax] => 1 [tax] => 0.2 ) [raw] => Array ( [with_tax] => 1.2 [without_tax] => 1 [tax] => 0.2 ) ) ) [is_variation] => [modifiers] => Array ( ) [images] => Array ( ) ) ) [pagination] => Array ( [total] => 1 [current] => 1 [limit] => 10 [offset] => 0 [from] => 1 [to] => 1 [offsets] => Array ( [first] => [previous] => [next] => [last] => ) [links] => Array ( [first] => [previous] => [next] => [last] => ) ) ) status = 1
How to get specific array from this list?
I already try
<?php
echo $product[0]['id'];
?>
it didn't work, show error Notice: Undefined offset: 0
you have a multidimensional array under the result key
access it the following way:
$product['result'][0]['id']
Give this a try:
echo $product['result'][0]['id'];
I have this array:
stdClass Object
(
[tid] => 26001835
[vid] => 5
[name] => AppleTV
[description] => My description
[format] => filtered_html
[weight] => 0
[vocabulary_machine_name] => how_to_watch_device
[field_device_image] => Array
(
[und] => Array
(
[0] => Array
(
[fid] => 26608990
[alt] =>
[title] =>
[width] => 194
[height] => 102
[uid] => 26000697
[filename] => Apple-TV.png
[uri] => public://Apple-TV.png
[filemime] => image/png
[filesize] => 2103
[status] => 1
[timestamp] => 1405346182
)
)
)
[field_buy_now_button_link] => Array
(
[und] => Array
(
[0] => Array
(
[value] => http://www.something.com
[format] =>
[safe_value] => http://www.something.com
)
)
)
[field_learn_more] => Array
(
[und] => Array
(
[0] => Array
(
[value] => http://something.com/somepage
[format] =>
[safe_value] => http://something.com/somepage
)
)
)
[field_device_category] => Array
(
[und] => Array
(
[0] => Array
(
[value] => network
)
)
)
)
stdClass Object
(
[tid] => 26001834
[vid] => 5
[name] => Playstation - USA
[description] => My description
[format] => filtered_html
[weight] => 2
[vocabulary_machine_name] => how_to_watch_device
[field_device_image] => Array
(
[und] => Array
(
[0] => Array
(
[fid] => 26608991
[alt] =>
[title] =>
[width] => 194
[height] => 102
[uid] => 26000697
[filename] => ps4network.png
[uri] => public://ps4network.png
[filemime] => image/png
[filesize] => 4566
[status] => 1
[timestamp] => 1405346218
)
)
)
[field_buy_now_button_link] => Array
(
[und] => Array
(
[0] => Array
(
[value] => http://www.somesite.com
[format] =>
[safe_value] => http://somesite.com
)
)
)
[field_learn_more] => Array
(
)
[field_device_category] => Array
(
[und] => Array
(
[0] => Array
(
[value] => blast_areas
)
)
)
)
stdClass Object
(
[tid] => 26001836
[vid] => 5
[name] => Brighthouse Networks
[description] => My description
[format] => filtered_html
[weight] => 3
[vocabulary_machine_name] => how_to_watch_device
[field_device_image] => Array
(
[und] => Array
(
[0] => Array
(
[fid] => 26608993
[alt] =>
[title] =>
[width] => 194
[height] => 102
[uid] => 26000697
[filename] => brighthouse.png
[uri] => public://brighthouse.png
[filemime] => image/png
[filesize] => 8392
[status] => 1
[timestamp] => 1405358781
)
)
)
[field_buy_now_button_link] => Array
(
)
[field_learn_more] => Array
(
)
[field_device_category] => Array
(
[und] => Array
(
[0] => Array
(
[value] => ppv_provider
)
)
)
)
I want to sort the array by the array by the value in field_device_category. Basically, I want to group the results but first I need to make sure all the objects are sorted by field_device_category.
Thanks in advance!
Use usort for this kind of sorting. It uses Quicksort in the background and takes a user-defined function to compare the array elements:
usort($array, "complicatedArrayComparer");
function complicatedArrayComparer($a,$b)
{
if ($a['field_device_category'] == $b['field_device_category']) {
return 0;
}
return ($a['field_device_category'] < $b['field_device_category']) ? -1 : 1;
}
How can I to have access to the "title" or "id" of my books in /me/books.reads (via graph api explorer I can see it, but not fetch it for my app).
I,ve trying
$books = $facebook->api('/me/book.reads','GET' );
foreach($books['data'] as $book) {
echo $book;
}
but doesn't work.
What I need to do?
UPDATE
Using print_r ($book);
Array ( [id] => 1404041189817636 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-11T05:23:56+0000 [publish_time] => 2013-08-11T05:23:56+0000 [application] => Array ( [name] => Books [id] => 174275722710475 ) [data] => Array ( [book] => Array ( [id] => 103118839728079 [url] => https://www.facebook.com/pages/O-alienista/103118839728079 [type] => books.book [title] => O alienista ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) ) Array ( [id] => 1402725673282521 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-08T12:06:56+0000 [end_time] => 2013-08-08T12:06:56+0000 [publish_time] => 2013-08-08T12:06:56+0000 [application] => Array ( [name] => cultdynamo-alfa [namespace] => cultdynamoalfa [id] => 486466824776147 ) [data] => Array ( [book] => Array ( [id] => 10151106849476668 [url] => http://samples.ogp.me/344468272304428 [type] => books.book [title] => Snow Crash ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) ) Array ( [id] => 1402724833282605 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-08T12:05:28+0000 [end_time] => 2013-08-08T12:05:28+0000 [publish_time] => 2013-08-08T12:05:28+0000 [application] => Array ( [name] => cultdynamo-alfa [namespace] => cultdynamoalfa [id] => 486466824776147 ) [data] => Array ( [book] => Array ( [id] => 10151106849476668 [url] => http://samples.ogp.me/344468272304428 [type] => books.book [title] => Snow Crash ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) ) Array ( [id] => 1402724089949346 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-08T12:02:20+0000 [end_time] => 2013-08-08T12:02:20+0000 [publish_time] => 2013-08-08T12:02:20+0000 [application] => Array ( [name] => cultdynamo-alfa [namespace] => cultdynamoalfa [id] => 486466824776147 ) [data] => Array ( [book] => Array ( [id] => 10151106849476668 [url] => http://samples.ogp.me/344468272304428 [type] => books.book [title] => Snow Crash ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) ) Array ( [id] => 1402724086616013 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-08T12:02:17+0000 [end_time] => 2013-08-08T12:02:17+0000 [publish_time] => 2013-08-08T12:02:17+0000 [application] => Array ( [name] => cultdynamo-alfa [namespace] => cultdynamoalfa [id] => 486466824776147 ) [data] => Array ( [book] => Array ( [id] => 10151106849476668 [url] => http://samples.ogp.me/344468272304428 [type] => books.book [title] => Snow Crash ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) ) Array ( [id] => 1402724056616016 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-08T12:02:05+0000 [end_time] => 2013-08-08T12:02:05+0000 [publish_time] => 2013-08-08T12:02:05+0000 [application] => Array ( [name] => cultdynamo-alfa [namespace] => cultdynamoalfa [id] => 486466824776147 ) [data] => Array ( [book] => Array ( [id] => 10151106849476668 [url] => http://samples.ogp.me/344468272304428 [type] => books.book [title] => Snow Crash ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) ) Array ( [id] => 1402246609997094 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-07T15:06:54+0000 [end_time] => 2013-08-07T15:06:54+0000 [publish_time] => 2013-08-07T15:06:54+0000 [application] => Array ( [name] => cultdynamo-alfa [namespace] => cultdynamoalfa [id] => 486466824776147 ) [data] => Array ( [book] => Array ( [id] => 10151106849476668 [url] => http://samples.ogp.me/344468272304428 [type] => books.book [title] => Snow Crash ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) ) Array ( [id] => 1402246209997134 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-07T15:05:16+0000 [end_time] => 2013-08-07T15:05:16+0000 [publish_time] => 2013-08-07T15:05:16+0000 [application] => Array ( [name] => cultdynamo-alfa [namespace] => cultdynamoalfa [id] => 486466824776147 ) [data] => Array ( [book] => Array ( [id] => 10151106849476668 [url] => http://samples.ogp.me/344468272304428 [type] => books.book [title] => Snow Crash ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) ) Array ( [id] => 1401338750087880 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-05T22:51:44+0000 [publish_time] => 2013-08-05T22:51:44+0000 [application] => Array ( [name] => Books [id] => 174275722710475 ) [data] => Array ( [book] => Array ( [id] => 10150941236166867 [url] => http://www.goodreads.com/book/show/13583337-clube-da-luta [type] => good_reads:book [title] => Clube da Luta ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) ) Array ( [id] => 1400891206799301 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-05T02:57:48+0000 [publish_time] => 2013-08-05T02:57:48+0000 [application] => Array ( [name] => Books [id] => 174275722710475 ) [data] => Array ( [book] => Array ( [id] => 10150604461117511 [url] => http://www.goodreads.com/book/show/6072069-cidade-de-deus [type] => good_reads:book [title] => Cidade De Deus ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) ) Array ( [id] => 1400890130132742 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-05T02:52:18+0000 [publish_time] => 2013-08-05T02:52:18+0000 [application] => Array ( [name] => Books [id] => 174275722710475 ) [data] => Array ( [book] => Array ( [id] => 108088695879860 [url] => https://www.facebook.com/pages/On-the-Road/108088695879860 [type] => books.book [title] => On the Road ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) ) Array ( [id] => 1400889916799430 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-05T02:51:27+0000 [publish_time] => 2013-08-05T02:51:27+0000 [application] => Array ( [name] => Books [id] => 174275722710475 ) [data] => Array ( [book] => Array ( [id] => 113172245363155 [url] => https://www.facebook.com/pages/Maus/113172245363155 [type] => books.book [title] => Maus ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) ) Array ( [id] => 1399682946920127 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-03T03:13:42+0000 [publish_time] => 2013-08-03T03:13:42+0000 [application] => Array ( [name] => Books [id] => 174275722710475 ) [data] => Array ( [book] => Array ( [id] => 108006402553308 [url] => https://www.facebook.com/pages/V-for-Vendetta/108006402553308 [type] => books.book [title] => V for Vendetta ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) )
You were basically improperly accessing the array. Based on the structure of the array, here's how you can access the title and id of the books:
$books = $facebook->api('/me/book.reads','GET' );
foreach ($books as $book)
{
echo "ID: ".$book['data']['book']['id'];
echo "Title: ".$book['data']['book']['title'];
}
Let me know if this works and makes sense to you :)
I am trying to access data inside a php object. I am confused about what the exact stynax is. Here is the output of the object:
stdClass Object ( [vid] => 10 [uid] => 1 [title] => Beachhead Don [log] =>
[status] => 1 [comment] => 1 [promote] => 0 [sticky] => 0 [ds_switch] => [nid] =>
10 [type] => product [language] => und [created] => 1357668665 [changed] => 1358198386
[tnid] => 0 [translate] => 0 [revision_timestamp] => 1358198386 [revision_uid] => 1
[model] => B 3000 [list_price] => 0.00000 [cost] => 0.00000 [sell_price] => 1.00000
[weight] => 0 [weight_units] => lb [length] => 0 [width] => 0 [height] => 0
[length_units] => in [pkg_qty] => 1 [default_qty] => 1 [unique_hash] =>
2eec0fcc8483f3a3541870fb24223296 [ordering] => 0 [shippable] => 0 [price] => 1.00000
[body] => Array ( [und] => Array ( [0] => Array ( [value] => Description info
))))))))))))))))))))))))))))))))))))))0 [summary] => [format] => filtered_html
[safe_value] =>Description info ))))))))))))))))))))))))))))))))))))))0[safe_summary]
=> ) ) ) [uc_product_image] => Array ( [und] => Array ( [0] => Array ( [fid] => 11
[alt] => [title] => [width] => 90 [height] => 120 [uid] => 1 [filename] =>
beachhead_don.jpg [uri] => public://beachhead_don.jpg [filemime] => image/jpeg
[filesize] => 14342 [status] => 1 [timestamp] => 1357668665 [rdf_mapping] => Array ( )
) ) ) [field_author] => Array ( [und] => Array ( [0] => Array ( [value] => John B.
Romesier [format] => [safe_value] => John B. Romesier ) ) ) [field_publisher] => Array
( [und] => Array ( [0] => Array ( [value] => Unknown [format] => [safe_value] =>
Unknown ) ) ) [field_release_date] => Array ( [und] => Array ( [0] => Array ( [value]
=> Mar 2012 [format] => [safe_value] => Mar 2012 ) ) ) [field_number_of_pages] => Array
( [und] => Array ( [0] => Array ( [value] => 123 ) ) ) [field_catagory] => Array (
[und] => Array ( [0] => Array ( [tid] => 4 ) ) ) [field_book_type] => Array ( [und] => Array ( [0] => Array ( [tid] => 1 ) ) ) [field_isbn] => Array ( ) [field_about_the_author] => Array ( [und] => Array ( [0] => Array ( [value] => Beachhed Don authoer............................ [format] => [safe_value] => Beachhed Don authoer............................ ) ) ) [rdf_mapping] => Array ( [rdftype] => Array ( [0] => sioc:Item [1] => foaf:Document ) [title] => Array ( [predicates] => Array ( [0] => dc:title ) ) [created] => Array ( [predicates] => Array ( [0] => dc:date [1] => dc:created ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [changed] => Array ( [predicates] => Array ( [0] => dc:modified ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [body] => Array ( [predicates] => Array ( [0] => content:encoded ) ) [uid] => Array ( [predicates] => Array ( [0] => sioc:has_creator ) [type] => rel ) [name] => Array ( [predicates] => Array ( [0] => foaf:name ) ) [comment_count] => Array ( [predicates] => Array ( [0] => sioc:num_replies ) [datatype] => xsd:integer ) [last_activity] => Array ( [predicates] => Array ( [0] => sioc:last_activity_date ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) ) [cid] => 0 [last_comment_timestamp] => 1357668665 [last_comment_name] => [last_comment_uid] => 1 [comment_count] => 0 [name] => admin [picture] => 0 [data] => b:0; [entity_view_prepared] => 1 )
I am trying to retrive the [value] of Description info ))))))))))))))))))))))))))))))))))))))0
I tried this
<?php
$node = menu_get_object(); //drupal code
if ( !empty($node) ) {
print $node ->body=>und=>0=>value;
}?>
and got an error about the '=' sign. What is the proper way to get my data?
[body] and [und] are arrays, so access them like this:
echo $node->body['und'][0]['value'];
It should be:
$node->body['und'][0]['value']
'Body' and 'und' are Arrays and need to be accessed with array syntax([]).
Accessing these values directly is sometimes frowned upon in drupal. You may want to look into: http://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_render/7