Carrot2 dcs language - carrot2

I've installed Carrot2 on a web application (PHP language). Everything works perfectly. Now i want to change the language of my results. I want to change english for french. I search on carrot2 documentation, on the web but i didn't find what i want (this link was usefull but it seems like the dcs folder had change since this post http://carrot2-users-and-developers-forum.607571.n2.nabble.com/Change-Language-in-DCS-REST-PHP-td639270.html). Anyway, i pass my paramaters (algo, query, source, etc.) with a simple form (and differents variables) and send them (PHP) to carrot2's method with curl. I tried different (strange or barbaric) ways to send french language :
$language = 'lang_fr'; // or $language = 'FRENCH'
$num = (isset($_GET["maxResult"])) ? $_GET["maxResult"] : "10";
$query = urlencode($_GET["query"]);
$source = "web";
$algorithm = "lingo";
$hierarchy = "max-hierarchy-depth";
$level_hierarchie= $_GET["deep"] ? $_GET["deep"] : "1";
$processor = new Carrot2Processor();
$job = new Carrot2Job();
$job->setSource($source);
$job->setQuery($query);
$job->setAlgorithm($algorithm);
$job->setAttribute("results", $num);
$job->setAttribute($hierarchy, $level_hierarchie);
i tried to set language like this in the setAttribute() funtion and of course it doesn't work.
$job->setAttribute("language", $language);
try {
$result = $processor->cluster($job);
} catch (Carrot2Exception $e) {
echo 'An error occurred during processing: ' . $e->getMessage();
exit(10);
}
I Also tried to change the CURLOPT_HTTPHEADER(add 'Accept-langugage: fr').
I see different responses but only for developpers using java and im using php. Is it possible to pass language choice with the setAttribute() method on PHP? Someone knows a way to do that?
Thank you in advance (i use carrot2-dcs-3.16)

For the eTools meta search engine, you can set the EToolsDocumentSource.language attribute directly in your calling code:
$job->setAttribute("EToolsDocumentSource.language", "FRENCH");
See the attribute documentation linked above for the list of supported languages.

Related

Using X-Editable - Backend part

So I'm just trying to use xeditable (http://vitalets.github.io/x-editable/docs.html#gettingstarted) to make changes to my database via AJAX.
Since I'm new to this concept and I'm (forcefully) working with PHP for the first time, I need some help.
I setup the frontend part, and a script called (say) script.php is handling the data for me (I need to write the new value in my database).
I can't really understand what to do in the script. Can someone guide me towards it? The docs above don't really do it for me.
Looking in a project I worked on a few months back (sorry about the mysql_ stuff – not my choice!)
Something like:
<?
include your/database/connection_stuff.php;
// Can't remember if x-editable passes the table in as well or not
$table = mysql_real_escape_string($_GET['table']);
// If not,
$table = 'name_of_table';
$value = mysql_real_escape_string($_POST['value']);
$name = mysql_real_escape_string($_POST['name']);
$pk = mysql_real_escape_string($_POST['pk']);
$result = mysql_query("UPDATE `$table` SET `$name` = '$value' WHERE id = '$pk'");
?>
Will do the trick.

Magento: get country name in a specified language

I use this code to get the country name,
Mage::getModel('directory/country')->loadByCode('DE')->getName();
in this sample I get "Germany". How can I get the translation of the country name to show for example "Deutschland" for the german language ?
Note: I don't use the code in a frontendend Module (it must be independant from the Frontend language of the customer).
Thanks a lot for help.
Of course Magento translation engine can be used in your external script:
Mage::getSingleton('core/translate')->init('de_DE', true);
$country_name = Mage::getModel('directory/country')->loadByCode('DE')->getName();
echo Mage::helper('core')->__($country_name);
Or you can use Zend_Locale class ar an alternative:
$locale = new Zend_Locale('de_DE');
$countries = $locale->getTranslationList('Territory', $locale->getLanguage(), 2);
echo $countries['DE'];

Migrating Wordpress Images to Drupal with Migrate 2.4

I'm having a time migrating images from Wordpress to Drupal with the Migrate 2.4 module. Here are my mappings:
$this->addFieldMapping('field_image','images');
$this->addFieldMapping('destination_file', 'images');
$this->addFieldMapping('field_image:source_dir')
->defaultValue('/Users/grafa/htdocs/wordpress/wp-content/uploads');
$this->addFieldMapping('field_image:file_class')
->defaultValue('MigrateFileUri');
The images come from a function that queries the wp_postmeta table then returns the result to the prepareRow() function.
function getImages($row) {
$post_id = $row->id;
$results = db_query("
SELECT pm.post_id, pm.meta_key, pm.meta_value FROM streetroots_wp.wp_postmeta AS pm LEFT JOIN streetroots_wp.wp_posts AS p ON pm.post_id=p.id WHERE p.post_parent = $post_id AND pm.meta_key='_wp_attached_file';");
$images = array();
foreach($results as $result) {
$images[] = $result->meta_value;
}
return !empty($images) ? $images : NULL;
}
This basically returns the image name and relative path from the wp_postmeta table something like '2012/05/figure1.jpg'. I then use prepareRow() like this:
function prepareRow($row) {
$row->images = $this->getImages($row);
}
I'm guessing there's something funky with how I'm using the new-ish migrate module that handles the file fields. The sql is outputs the file names correctly but it doesn't seem like the images are getting copied over. This is a Drupal 7 using Migrate 2.4. Any help is appreciated.
You might want to have a look at the beer.inc lines 377 - 383 within migrate_example folder and at the associated content type *migrate_example_beer* which has an image field defined not a file field which was my mistake and lead to my images not being populated.
Hope this helps!
Migrate 2.5 has largely simplified the handling of files, you should check it out!

Magento 1.12 and Solr 3.6 No proper results and no spell suggestions

Any idea or suggestion. I am kind of confuse , I have setup solr and magento couple of times but now with magento 1.12 its behaving strange no proper results and no spell check.
We had our magento 1.11 working fine with solr 1.4 ,its still working fine I try to use 1.4 and solr 3.6 no fix.
Any idea or suggestion. I am kind of confuse
We have found multiple problems with solr with Magento EE 1.12.
If you run the fulltext indexer from the shell via a cronjob the following event (yes it is spelled incorrectly) "catelogsearch_searchable_attributes_load_after" will not be dispatched and this method will not be run: storeSearchableAttributes. This prevented all the fulltext attributes from being sent in the Solr Documents. The solution is to run it from the GUI BUT you must extend your php timeout in .htaccess and probably extend php memory limit as well. I will probably hardcode it somewhere because you obviously don't want such a long timeout for your website visitors.
I recommend enabling "partial commit" in the magento admin gui.
Pay attention to the solr log when you are running this indexer. It gives valuable clues. We had two issues which were causing severe errors in solr. One where a "*" was being escaped to "\*" incorrectly.
We overrode it by creating a local override from core where we check !== "*":
app/code/local/Enterprise/Search/Model/Adapter/Solr/Abstract.php
foreach ($facetFieldConditions as $facetCondition) {
if (is_array($facetCondition) && isset($facetCondition['from'])
&& isset($facetCondition['to'])) {
$from = (isset($facetCondition['from']) && strlen(trim($facetCondition['from'])) && trim($facetCondition['from']) !== "*")
? $this->_prepareQueryText($facetCondition['from'])
: '*';
$to = (isset($facetCondition['to']) && strlen(trim($facetCondition['to'])) && trim($facetCondition['to']) !== "*")
We also had a case where an attribute that was set to multiselect could have no options chosen. Long story short when the array was empty it resulted in an empty string being appended which threw an error. The solution was to first check if the array was empty.
So we had to override with app/code/local/Enterprise/Search/Model/Adapter/Abstract.php
if (!empty($val)) {
$preparedValue = array_merge($preparedValue, explode(',', $val));
}
We also just fixed a problem where product with select/multi-select attributes were being sent with blank labels to solr. This caused the indexer to fail to complete.
We overrode app/code/core/Enterprise/Search/Model/Adapter/Abstract.php and will make a local module to override this correctly.
Here's the fix
--- a/app/code/core/Enterprise/Search/Model/Adapter/Abstract.php
+++ b/app/code/local/Enterprise/Search/Model/Adapter/Abstract.php
## -434,6 +434,10 ## abstract class Enterprise_Search_Model_Adapter_Abstract
foreach ($preparedValue as $id => $val) {
$preparedValue[$id] = $attribute->getSource()->getOptionText($val);
}
+
+ $preparedValue = array_filter($preparedValue);
+ $preparedNavValue = array_filter($preparedNavValue);
+
} else {
$preparedValue = $value;
if ($backendType == 'datetime') {

CodeIgniter: current_url shows question mark

Say my page is on:
http://localhost/app1/profile/index/123/
The result of current_url() is this:
http://localhost/app1/?profile/index/123
There is a ? that shouldn't be there. The question mark seems to be caused by the following config setting:
$config['enable_query_strings'] = TRUE;
I need query strings enabled in my application. Any ideas what I need to do?
EDIT 1:
Also, in the case when the URL does have a query string, I need current_url to also return that. I'm hoping Phil Sturgeon's solution here CodeIgniter current_url doesn't show query strings will help me.
I'm using CI 2.1.0.
As mentioned, $config['enable_query_strings'] is sort of a "legacy" setting in Codeigniter from back when there was no support $_GET (really, none).
http://codeigniter.com/user_guide/general/urls.html
Enabling Query Strings
In some cases you might prefer to use query strings URLs:
index.php?c=products&m=view&id=345
c === Your controller name
m === Your method name
The rest is the method arguments. It's a very misleading description, and there's no mention of the other setting or query strings at all in the rest of the URL docs. I've never heard of anyone actually using this. CI comes with $config['allow_get_array']= TRUE; by default, which is what you want.
You can modify the current_url() function for query string support, just create application/helpers/MY_url_helper.php and use this:
function current_url($query_string = FALSE)
{
$CI =& get_instance();
$current_url = $CI->config->site_url($CI->uri->uri_string());
// BEGIN MODIFICATION
if ($query_string === TRUE)
{
// Use your preferred method of fetching the query string
$current_url .= '?'.http_build_query($_GET);
}
// END MODIFICATION
return $current_url;
}
Then call it like current_url(TRUE) to include the query string.
Don't use: $config['enable_query_strings'] = TRUE;
Use this instead: $config['allow_get_array']= TRUE;
enable_query_strings is not what you think and is not used much.
To build your own query strings, use one of these two:
$query_string = http_build_query($this->input->get());
$query_string = $this->input->server('QUERY_STRING');
along with this:
$lastseg_with_query = $lastseg.'?'.$query_string;
Please consult this SO Q&A for more information: URI Segment with Question Mark

Resources