Advertisement:

Author Topic: Search result  (Read 397 times)

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Search result
« on: April 03, 2019, 12:11:42 pm »
Please someone explain me about osclass search result list ordering system! I want to know more about this! For example when we search for something, and it orders the result, ordering is based on what? Based on old post to new post? Or exactly what? For example if there is 2 items with the same title but different published date, which one listed first on search result list?
Where is the code exactly? The code that shows the result list order on loop on search.php after we push the apply button!
Not the code for searching and finding the items. the code for ordering the result list on search.php.
Thanks

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2155
  • osclass.work
Re: Search result
« Reply #1 on: April 03, 2019, 04:21:41 pm »
Not the code for searching and finding the items. the code for ordering the result list on search.php.

These are two contradicting statements, to me at least. Search is always about 'finding', regardless of input.

In any case, by default, ordering is by date from latest (newest) to oldest.

Quote
For example if there is 2 items with the same title but different published date, which one listed first on search result list?

By default, again, they will be sorted by date, newer one first. You can easily verify this by yourself.

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Search result
« Reply #2 on: April 03, 2019, 10:14:46 pm »
Quote
By default, again, they will be sorted by date, newer one first. You can easily verify this by yourself.

Yes i know that! But i just asked this question to find out where this exactly happens by code!
Please address me the code exactly this happens!
Not the whole script! Just the line of code that this happens!
Thanks,

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2155
  • osclass.work
Re: Search result
« Reply #3 on: April 04, 2019, 01:08:30 am »
Look in search model and controller, it's not exactly 'one line', you have to understand the code flow.

Web-Media

  • Sr. Member
  • ****
  • Posts: 453
  • Web
Re: Search result
« Reply #4 on: April 04, 2019, 01:09:33 am »
Code: [Select]
 osclass / Osclass

Code Issues 84 Pull requests 20 Projects 0 Wiki Pulse

oc-includes/osclass/model/Search.php

<?php if ( !defined('ABS_PATH') ) exit('ABS_PATH is not loaded. Direct access is not allowed.');

/*

* Copyright 2014 Osclass

*

* Licensed under the Apache License, Version 2.0 (the "License");

* you may not use this file except in compliance with the License.

* You may obtain a copy of the License at

*

* http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable law or agreed to in writing, software

* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

* See the License for the specific language governing permissions and

* limitations under the License.

*/

/**

*

*/

class Search extends DAO

{

/**

*

* @var type

*/

private $conditions;

private 
$itemConditions;

private 
$tables;

private 
$tables_join// ?

private $sql;

private 
$order_column;

private 
$order_direction;

private 
$limit_init;

private 
$results_per_page;

private 
$cities;

private 
$city_areas;

private 
$regions;

private 
$countries;

private 
$categories;

private 
$search_fields;

private 
$total_results;

private 
$total_results_table;

private 
$sPattern;

private 
$sEmail;

private 
$groupBy;

private 
$having;

private 
$locale_code;

private 
$withPattern;

private 
$withPicture;

private 
$withLocations;

private 
$withCategoryId;

private 
$withUserId;

private 
$withItemId;

private 
$withNoUserEmail;

private 
$onlyPremium;

private 
$price_min;

private 
$price_max;

private 
$user_ids;

private 
$itemId;

private 
$userTableLoaded;

private static 
$instance;

public static function 
newInstance()

{

if( !
self::$instance instanceof self ) {

self::$instance = new self;

}

return 
self::$instance;

}

/**

*

*/

function __construct($expired false)

{

parent::__construct();

$this->setTableName('t_item');

$this->setFields( array('pk_i_id') );

$this->withPattern false;

$this->withLocations false;

$this->withCategoryId false;

$this->withUserId false;

$this->withPicture false;

$this->withNoUserEmail false;

$this->onlyPremium false;

$this->price_min null;

$this->price_max null;

$this->user_ids null;

$this->itemId null;

$this->userTableLoaded false;

$this->city_areas = array();

$this->cities = array();

$this->regions = array();

$this->countries = array();

$this->categories = array();

$this->conditions = array();

$this->tables = array();

$this->tables_join = array();

$this->search_fields = array();

$this->itemConditions = array();

$this->locale_code = array();

$this->groupBy '';

$this->having '';

$this->order();

$this->limit();

$this->results_per_page 10;

if(!
$expired) {

// t_item

$this->addItemConditions(sprintf("%st_item.b_enabled = 1 "DB_TABLE_PREFIX));

$this->addItemConditions(sprintf("%st_item.b_active = 1 "DB_TABLE_PREFIX));

$this->addItemConditions(sprintf("%st_item.b_spam = 0"DB_TABLE_PREFIX));

$this->addItemConditions(sprintf("(%st_item.b_premium = 1 || %st_item.dt_expiration >= '%s')"DB_TABLE_PREFIXDB_TABLE_PREFIXdate('Y-m-d H:i:s')) );

}

$this->total_results null;

$this->total_results_table null;

// get all item_location data

if(OC_ADMIN) {

$this->addField(sprintf('%st_item_location.*'DB_TABLE_PREFIX) );

}

}

/**

* Return an array with columns allowed for sorting

*

* @return array

*/

public static function getAllowedColumnsForSorting()

{

return( array(
'i_price''dt_pub_date''dt_expiration') );

}

/**

* Return an array with type of sorting

*

* @return array

*/

public static function getAllowedTypesForSorting()

{

return ( array (
=> 'asc'=> 'desc') );

}

// juanramon: little hack to get alerts work in search layout

public function reconnect()

{

// $this->conn = getConnection();

}

/**

* Add conditions to the search

*

* @access public

* @since unknown

* @param mixed $conditions

*/

public function addConditions($conditions)

{

if(
is_array($conditions)) {

foreach(
$conditions as $condition) {

$condition trim($condition);

if(
$condition!='') {

if(!
in_array($condition$this->conditions)) {

$this->conditions[] = $condition;

}

}

}

} else {

$conditions trim($conditions);

if(
$conditions!='') {

if(!
in_array($conditions$this->conditions)) {

$this->conditions[] = $conditions;

}

}

}

}

/**

* Add item conditions to the search

*

* @access public

* @since unknown

* @param mixed $conditions

*/

public function addItemConditions($conditions)

{

if(
is_array($conditions)) {

foreach(
$conditions as $condition) {

$condition trim($condition);

if(
$condition!='') {

if(!
in_array($condition$this->itemConditions)) {

$this->itemConditions[] = $condition;

}

}

}

} else {

$conditions trim($conditions);

if(
$conditions!='') {

if(!
in_array($conditions$this->itemConditions)) {

$this->itemConditions[] = $conditions;

}

}

}

}

/**

* Add locale conditions to the search

*

* @access public

* @since 3.2

* @param string $locale

*/

public function addLocale($locale)

{

if(
is_array($locale)) {

foreach(
$locale as $l) {

if(
$l!='') {

$this->locale_code[$l] = $l;

}

}

} else {

if(
$locale!='') {

$this->locale_code[$locale] = $locale;

}

}

}

/**

* Add new fields to the search

*

* @access public

* @since unknown

* @param mixed $fields

*/

public function addField($fields)

{

if(
is_array($fields)) {

foreach(
$fields as $field) {

$field trim($field);

if(
$field!='') {

if(!
in_array($field$this->fields)) {

$this->search_fields[] = $field;

}

}

}

} else {

$fields trim($fields);

if(
$fields!='') {

if(!
in_array($fields$this->fields)) {

$this->search_fields[] = $fields;

}

}

}

}

/**

* Add extra table to the search

*

* @access public

* @since unknown

* @param mixed $tables

*/

public function addTable($tables)

{

if(
is_array($tables)) {

foreach(
$tables as $table) {

$table trim($table);

if(
$table!='') {

if(!
in_array($table$this->tables)) {

$this->tables[] = $table;

}

}

}

} else {

$tables trim($tables);

if(
$tables!='') {

if(!
in_array($tables$this->tables)) {

$this->tables[] = $tables;



Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Search result
« Reply #5 on: April 04, 2019, 04:36:15 am »
Look in search model and controller, it's not exactly 'one line', you have to understand the code flow.

I didn't say one line! I said all the lines related to this purpose!

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Search result
« Reply #6 on: April 04, 2019, 04:39:10 am »
Code: [Select]
osclass / Osclass

Code Issues 84 Pull requests 20 Projects 0 Wiki Pulse

oc-includes/osclass/model/Search.php

<?php if ( !defined('ABS_PATH') ) exit('ABS_PATH is not loaded. Direct access is not allowed.');

/*

* Copyright 2014 Osclass

*

* Licensed under the Apache License, Version 2.0 (the "License");

* you may not use this file except in compliance with the License.

* You may obtain a copy of the License at

*

* http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable law or agreed to in writing, software

* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

* See the License for the specific language governing permissions and

* limitations under the License.

*/

/**

*

*/

class Search extends DAO

{

/**

*

* @var type

*/

private $conditions;

private 
$itemConditions;

private 
$tables;

private 
$tables_join// ?

private $sql;

private 
$order_column;

private 
$order_direction;

private 
$limit_init;

private 
$results_per_page;

private 
$cities;

private 
$city_areas;

private 
$regions;

private 
$countries;

private 
$categories;

private 
$search_fields;

private 
$total_results;

private 
$total_results_table;

private 
$sPattern;

private 
$sEmail;

private 
$groupBy;

private 
$having;

private 
$locale_code;

private 
$withPattern;

private 
$withPicture;

private 
$withLocations;

private 
$withCategoryId;

private 
$withUserId;

private 
$withItemId;

private 
$withNoUserEmail;

private 
$onlyPremium;

private 
$price_min;

private 
$price_max;

private 
$user_ids;

private 
$itemId;

private 
$userTableLoaded;

private static 
$instance;

public static function 
newInstance()

{

if( !
self::$instance instanceof self ) {

self::$instance = new self;

}

return 
self::$instance;

}

/**

*

*/

function __construct($expired false)

{

parent::__construct();

$this->setTableName('t_item');

$this->setFields( array('pk_i_id') );

$this->withPattern false;

$this->withLocations false;

$this->withCategoryId false;

$this->withUserId false;

$this->withPicture false;

$this->withNoUserEmail false;

$this->onlyPremium false;

$this->price_min null;

$this->price_max null;

$this->user_ids null;

$this->itemId null;

$this->userTableLoaded false;

$this->city_areas = array();

$this->cities = array();

$this->regions = array();

$this->countries = array();

$this->categories = array();

$this->conditions = array();

$this->tables = array();

$this->tables_join = array();

$this->search_fields = array();

$this->itemConditions = array();

$this->locale_code = array();

$this->groupBy '';

$this->having '';

$this->order();

$this->limit();

$this->results_per_page 10;

if(!
$expired) {

// t_item

$this->addItemConditions(sprintf("%st_item.b_enabled = 1 "DB_TABLE_PREFIX));

$this->addItemConditions(sprintf("%st_item.b_active = 1 "DB_TABLE_PREFIX));

$this->addItemConditions(sprintf("%st_item.b_spam = 0"DB_TABLE_PREFIX));

$this->addItemConditions(sprintf("(%st_item.b_premium = 1 || %st_item.dt_expiration >= '%s')"DB_TABLE_PREFIXDB_TABLE_PREFIXdate('Y-m-d H:i:s')) );

}

$this->total_results null;

$this->total_results_table null;

// get all item_location data

if(OC_ADMIN) {

$this->addField(sprintf('%st_item_location.*'DB_TABLE_PREFIX) );

}

}

/**

* Return an array with columns allowed for sorting

*

* @return array

*/

public static function getAllowedColumnsForSorting()

{

return( array(
'i_price''dt_pub_date''dt_expiration') );

}

/**

* Return an array with type of sorting

*

* @return array

*/

public static function getAllowedTypesForSorting()

{

return ( array (
=> 'asc'=> 'desc') );

}

// juanramon: little hack to get alerts work in search layout

public function reconnect()

{

// $this->conn = getConnection();

}

/**

* Add conditions to the search

*

* @access public

* @since unknown

* @param mixed $conditions

*/

public function addConditions($conditions)

{

if(
is_array($conditions)) {

foreach(
$conditions as $condition) {

$condition trim($condition);

if(
$condition!='') {

if(!
in_array($condition$this->conditions)) {

$this->conditions[] = $condition;

}

}

}

} else {

$conditions trim($conditions);

if(
$conditions!='') {

if(!
in_array($conditions$this->conditions)) {

$this->conditions[] = $conditions;

}

}

}

}

/**

* Add item conditions to the search

*

* @access public

* @since unknown

* @param mixed $conditions

*/

public function addItemConditions($conditions)

{

if(
is_array($conditions)) {

foreach(
$conditions as $condition) {

$condition trim($condition);

if(
$condition!='') {

if(!
in_array($condition$this->itemConditions)) {

$this->itemConditions[] = $condition;

}

}

}

} else {

$conditions trim($conditions);

if(
$conditions!='') {

if(!
in_array($conditions$this->itemConditions)) {

$this->itemConditions[] = $conditions;

}

}

}

}

/**

* Add locale conditions to the search

*

* @access public

* @since 3.2

* @param string $locale

*/

public function addLocale($locale)

{

if(
is_array($locale)) {

foreach(
$locale as $l) {

if(
$l!='') {

$this->locale_code[$l] = $l;

}

}

} else {

if(
$locale!='') {

$this->locale_code[$locale] = $locale;

}

}

}

/**

* Add new fields to the search

*

* @access public

* @since unknown

* @param mixed $fields

*/

public function addField($fields)

{

if(
is_array($fields)) {

foreach(
$fields as $field) {

$field trim($field);

if(
$field!='') {

if(!
in_array($field$this->fields)) {

$this->search_fields[] = $field;

}

}

}

} else {

$fields trim($fields);

if(
$fields!='') {

if(!
in_array($fields$this->fields)) {

$this->search_fields[] = $fields;

}

}

}

}

/**

* Add extra table to the search

*

* @access public

* @since unknown

* @param mixed $tables

*/

public function addTable($tables)

{

if(
is_array($tables)) {

foreach(
$tables as $table) {

$table trim($table);

if(
$table!='') {

if(!
in_array($table$this->tables)) {

$this->tables[] = $table;

}

}

}

} else {

$tables trim($tables);

if(
$tables!='') {

if(!
in_array($tables$this->tables)) {

$this->tables[] = $tables;



This is the code for whole search!
I just need the part that orders listing in loop after search!

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Search result
« Reply #7 on: April 04, 2019, 04:47:18 am »
the reason that I'm looking for this is to change the search result list order!
I don't want to order the result by date!
I want the result order be randomized! Each time user push the Apply button to search, it shows the result list completely different than before! Each time be different! Shows the result list randomly each time for user!

If we find that part of the code, then we could put (randomized function) instead!
« Last Edit: April 04, 2019, 04:52:20 am by Sophia_OS »

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Search result
« Reply #8 on: April 10, 2019, 01:36:19 am »
Please Help to solve this topic! Thanks!

Web-Media

  • Sr. Member
  • ****
  • Posts: 453
  • Web
Re: Search result
« Reply #9 on: April 11, 2019, 09:54:22 pm »
Like i've told before .
https://www.freelancer.com/job-search/osclass/#
Customizations to your tailored needs done fast and at a good price

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Search result
« Reply #10 on: April 11, 2019, 11:52:05 pm »
@Web-Media Thank you very much for recommendation!
This idea is something that i want to share with others!
Would you please tell me where is exactly (listing the result) code? I want to find that code and replace with my randomized function!
Thanks,

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Search result
« Reply #11 on: April 11, 2019, 11:56:56 pm »
Look in search model and controller, it's not exactly 'one line', you have to understand the code flow.

Would you please help me to find this part of code? I want to find that and put my randomized function instead!