I want to search across multiple languages (translations), but when I do duplicate results are returned for each language. I am using Drupal with Search API Solr for the indexing. The results look like the following:
[results] => Array
(
[3239/en] => Array
(
[id] => 3239/en
[score] => 1
[fields] => Array
(
[search_api_id] => 3239/en
[search_api_relevance] => 1
)
)
[3240/en] => Array
(
[id] => 3240/en
[score] => 1
[fields] => Array
(
[search_api_id] => 3240/en
[search_api_relevance] => 1
)
)
So the id and language are both contained in the key/id. Currently I can filter by a language using the code:
$index = search_api_index_load('default_multilingual_node_index');
$query = $index->query();
$query->keys($search_terms);
$filter = $query->createFilter('OR');
$filter->condition('search_api_language', $language);
$query->filter($filter);
$results = $query->execute();
I have been looking for a way (either Solr config, or Drupal Search API call) to be able to search across multiple languages without the duplicates to no avail. Are there any solutions?
Are you using the below modules
https://www.drupal.org/project/apachesolr_multilingual (for drupal 7)
https://www.drupal.org/project/search_api_solr_multilingual (for drupal 8)
Better support for non-English languages and support for multilingual search
Related
I'm trying to use Twig (inside Symfony2) to debug a variable that contains a multidimensional array, yet it only outputs up to three arrays deep:
array
'Coating' =>
array
'type' => string 'single' (length=6)
'data' =>
array
0 =>
array
...
1 =>
array
...
2 =>
array
...
Whereas a print_r would generate
Array
(
[Coating] => Array
(
[type] => single
[data] => Array
(
[0] => Array
(
[id] => 1
[selectable] => 1
[name] => Front
)
[1] => Array
(
[id] => 7
[selectable] => 1
[name] => Back
)
[2] => Array
(
[id] => 13
[selectable] => 1
[name] => Both Sides
)
)
)
)
The reason I'd like Twig to do the debugging is that printing code prior to my template being rendered completely jumbles the output of a given page -- I'd like to print the data where it is easily read.
I don't understand why a "debug" would truncate data...
Edit: The debugging is through the use of {% debug foobar %} with that tag enabled through the inclusion of the following in my app's configuration:
services:
twig.extension.debug:
class: Twig_Extensions_Extension_Debug
tags: [ { name: 'twig.extension' } ]
I just read the source code of the twig debug extension (class Twig_Extensions_Node_Debug) and it doesn't truncate the var_dump. It is probably xdebug that is truncating: I cite a comment on the var_dump php.net documentation:
Keep in mind if you have xdebug installed it will limit the var_dump()
output of array elements and object properties to 3 levels deep.
To change the default, edit your xdebug.ini file and add the
folllowing line: xdebug.var_display_max_depth=n
I have an issue for searching on elastic. I use NEST library for search and I try to get records that is customername field start with 'GÖKDEMİR' (for example)
var response = await _elasticClient.SearchAsync<AccountAddressInfo>(p => p
.Query(q => q
.MatchPhrasePrefix(m => m
.Field(f => f.CustomerName)
.Query(filter.CustomerName)
)
)
.Size(101));
With this search, I get the record on response that contains 'GÖKDEMİR' in customername field but I want to get fields starts with 'GÖKDEMİR'.
How can I do this.
In case your customername field is a term type, then you can try to use just Prefix where you are using MatchPhrasePrefix like so :
.Query(q => q
.Prefix(m => m
.Field(f => f.CustomerName)
.Query(filter.CustomerName)
)
)
.Size(101));
There doesn't seem to be any details about this in the forms api. So please forgive my question, but I need to know what is being returned when i submit values from a form field where I can select multiple values. I suspect it is an array, if so, how is it structured? Thanks.
Here is a dump of the value field from the $form_state variable after submission for a form that contains 2 multiple select lists. *Countries and Currencies. As you can see, you are correct, an array of values corresponding to the selected option values is returned for each of the 2 lists:
[values] => Array
(
[name] => PayPal
[ppid] => 17
[countries] => Array
(
[236] => 236
[237] => 237
)
[currencies] => Array
(
[USD] => USD
[EUR] => EUR
[CAD] => CAD
)
[submit] => Submit Details
[form_build_id] => form-d675700e434f656b0e1c7ac4aa91a210
[form_token] => 3405b88547c068a0f6a2742670b2149a
[form_id] => add_payment_method_form
[op] => Submit Details
)
I have a products model with 2 many to many relationships defined.
protected $_has_many = array
(
'foodcats' => array('model' => 'foodcat', 'through' => 'products_foodcats'),
'foodgroups' => array('model' => 'foodgroup', 'through' => 'products_foodgroups')
)
I need a query where I find products with a given foodcat id and a given foodgroup name.
I know I can do the following to get all products with a given foodcat id
$foodcat = ORM::factory('foodcat',$foodCatId);
$products = $foodcat->products->find_all();
But how do I query for products in that foodcat that also are in the foodgroup 'Entrees'?
Thanks!
Simply; you don't. What you need is INNER JOIN, like;
ORM::factory('product')
->join('foodcats','INNER')
->on('foodcats.id','=',$foodcats_id)
->join('foodgroups','INNER')
->on('foodgroups.name','=',$foodgroups_name)
->find_all();
in Kohana 3.1 without using DB::expr, will give unknown column error.
ORM::factory('product')
->join('foodcats','INNER')
->on('foodcats.id','=', DB::expr($foodcats_id))
->join('foodgroups','INNER')
->on('foodgroups.name','=', DB::expr($foodgroups_name))
->find_all();
I have a statement in my template.php file that directs to a custom node-myccktype.tpl.php. I've added some DIV's so that I can have a two column node/add form, but now I'm trying to find print my fields, but can't seem to get it.
I'm basically using something like this:
<?php print form_render($form['field_sr_minutes']); ?>
which I came across on a Drupal Blog, but I get call to undefined function "form_render"
I am using the var_dump to get the the array below, how can I print my node title(subject) field without printing everything else? This way I can put each form field in the column I want Instead of the standard vertical drupal form.
Array
(
[0] => Array
(
[#type] => textfield
[#title] => Subject
[#required] => 1
[#default_value] =>
[#maxlength] => 255
[#weight] => -5
[#post] => Array
(
)
[#programmed] =>
[#tree] =>
[#parents] => Array
(
[0] => title
)
[#array_parents] => Array
(
[0] => title
)
[#processed] => 1
[#description] =>
[#attributes] => Array
(
)
[#input] => 1
[#size] => 60
[#autocomplete_path] =>
[#process] => Array
(
[0] => form_expand_ahah
)
[#name] => title
[#id] => edit-title
[#value] =>
[#defaults_loaded] => 1
[#sorted] => 1
)
Sorry. Because of your .tpl file name I thought that you were trying to theme a node view. For forms, the right function is not form_render but drupal_render. You can basically write things like echo drupal_render($form['field_sr_minutes']) . In the very end, remember to do a drupal_render($form) to render all the remaining things which you have not rendered by hand. This will be required to have the form working correctly.
Old Answer
The node.tpl.php and other content
type specific .tpl.php get passed the
full node object in $node. Try doing
a
drupal_set_message(print_r($node,TRUE))
on top of your tpl file. From that you
can figure out the exact path of the
values you need to print.
For example, title of the node will be
available in $node->title. However you
should be careful to always use
check_plain if you are going to
print user submitted values. For CCK
fields, you can find the already
filtered values in $node-><field
name>[0][view].