Dynamic fields for my index not coming up in the list of fields - indexing

I am trying to get the fields of my index using the below code snippet.
var fieldsList= DocumentStore.DatabaseCommands.GetIndex("IndexName").Fields.ToList();
This is returning a string list with all fields defined in the index except the dynamic fields ( fields returned from _ ).
Here is the Map command for my index.
Map = products =>
from product in product s
select new
{
product.Title,
product.Subject,
product.From,
_ = product.
Attributes.Select(attribute =>
CreateField(attribute.Name, attribute.Value, false, true))
};

That is by design. The list of fields is the static fields that are in your index.
We don't try to find the dynamic ones.

Related

getProduct()->getTag() return null, when it should return tags associated to the Product

In my project, we have products that has tag called serviceItem. Those item with that tag when ordered should be separated by the quantity into individuals order.
It issue is that getTags() returns null, and getTagIds gets "Call to a member function getTagIds() on null" when it gets to the next loop.
Is there a reason for why getTags() returns null?
private function transformOrderLines(OrderEntity $order): array
{
/**
* TODO: If we need to send advanced prices,
* the price value of the the lines array should be changed to caldulate the advanced price,
* with the built in quantity calculator
*/
$lines = [];
foreach ($order->getLineItems() as $orderLine) {
$hasDsmServiceItemTag = $orderLine->getProduct()->getTags();
$lines[] = [
'name' => $orderLine->getLabel(),
'sku' => substr($orderLine->getProduct()->getProductNumber(), 0, 19),
'price' => (string) ($orderLine->getProduct()->getPrice()->first()->getNet()
* $order->getCurrencyFactor()), //gets original price, calculates factor
'quantity' => (string) $orderLine->getQuantity()
];
}
$shipping = $this->transformShipping($order);
if ($shipping) {
$lines = array_merge($lines, $shipping);
}
return $lines;
}`
I also tried $orderLine->getProduct()->getTags()->getName() it also return "Call to a member function getTags() on null"
The problem is wherever the $order is fetched from the DB the orderLineItem.product.tag association is not included in the criteria.
For performance reasons shopware does not lazily load all association when you access them on entities, but you have to exactly define which associations should be included when you fetch the entities from the database.
For the full explanation take a look at the docs.

Not able to put tag column value on monday item

I am trying to use python to automation common Monday tasks. I am able to create an item in the board but the column (type=tag) is not updating.
I used this tutorial:
https://support.monday.com/hc/en-us/articles/360013483119-API-Quickstart-Tutorial-Python#
Here is my graphql code that I am executing:
query = 'mutation ($device: String!, $columnVals: JSON!) { create_item (board_id:<myboardid>, item_name:$device, column_values:$columnVals) { id } }'
vars = {'device': device,
'columnVals': json.dumps({
'cloud_name6': {'text': cloudname} # this is where i want to add a tag. cloud_name6 is id of the column.
})
}
data = {'query' : query, 'variables' : vars}
r = requests.post(url=apiUrl, json=data, headers=headers) print(r.json())
I have tried changing id to title as key in the Json string but no luck. I fetched the existing item and tried to add exact json string but still no luck. I also tried below json data without any luck
'columnVals': json.dumps({
'cloud_name6': cloudname
})
Any idea what's wrong with the query?
When creating or mutating tag columns via item queries, you need to send an array of ids of the tags ("tag_ids") that are relating to this item. You don't set or alter tag names via an item query.
Corrected Code
'columnVals': json.dumps({
'cloud_name6': {'tag_ids': [295026,295064]}
})
https://developer.monday.com/api-reference/docs/tags

Linq2DB can't translate a mapped column in Where clause

I'm working with a legacy Oracle database that has a column on a table which stores boolean values as 'Y' or 'N' characters.
I have mapped/converted this column out like so:
MappingSchema.Default.SetConverter<char, bool>(ConvertToBoolean);
MappingSchema.Default.SetConverter<bool, char>(ConvertToChar);
ConvertToBoolean & ConvertToChar are simply functions that map between the types.
Here's the field:
private char hasDog;
[Column("HAS_DOG")]
public bool HasDog
{
get => ConvertToBoolean(hasDog);
set => hasDog = ConvertToChar(value);
}
This has worked well for simply retrieving data, however, it seems the translation of the following:
var humanQuery = (from human in database.Humans
join vetVisit in database.VetVisits on human.Identifier equals vetVisit.Identifier
select new HumanModel(
human.Identifier
human.Name,
human.HasDog,
vetVisit.Date,
vetVisit.Year,
vetVisit.PaymentDue
));
// humanQuery is filtered by year here
var query = from vetVisits in database.VetVisits
select new VetPaymentModel(
(humanQuery).First().Year,
(humanQuery).Where(q => q.HasDog).Sum(q => q.PaymentDue), -- These 2 lines aren't correctly translated to Y/N
(humanQuery).Where(q => !q.HasDog).Sum(q => q.PaymentDue)
);
As pointed out above, the .Where clause here doesn't translate the boolean comparison of HasDog being true/false to the relevant Y/N values, but instead a 0/1 and results in the error
ORA-01722: invalid number
Is there any way to handle this case? I'd like the generated SQL to check that HAS_DOG = 'Y' for instance with the specified Where clause :)
Notes
I'm not using EntityFramework here, the application module that this query exists in doesn't use EF/EFCore
You can define new mapping schema for your particular DataConnection:
var ms = new MappingSchema();
builder = ms.GetFluentMappingBuilder();
builder.Entity<Human>()
.Property(e => e.HasDog)
.HasConversion(v => v ? 'Y' : 'N', p => p == 'Y');
Create this schema ONCE and use when creating DataConnection

Optional term in ContentSearch query

I'm trying to build a lucene query through Sitecore ContentSearch that includes an optional term. The optional term is used to boost certain results. The lucene query should look like this:
+(+(_content:myquery keywords:myquery) boostfield:boostdata)
How can I construct such a query? With PredicateBuilder I can only add And / Or expressions.
Here's an example of how I construct the predicate:
var contentPredicate = PredicateBuilder.Create<MySearchResultItem>(p => p.Content == parameters.QueryString);
contentPredicate = contentPredicate.Or(k => k.Keywords == "myquery");
mainPredicate = mainPredicate.And(contentPredicate);
mainPredicate = mainPredicate.And(f => f["boostfield"] == "boostdata");
This will make "boostfield" a must field wich is not what I need (note the + before the field name):
+(+(_content:myquery keywords:myquery) +boostfield:boostdata)
Is there a way to accomplish this?
Try This:
var contentPredicate = PredicateBuilder.Create<MySearchResultItem>(p => p.Content == parameters.QueryString);
contentPredicate = contentPredicate.Or(k => k.Keywords == "myquery");
mainPredicate = mainPredicate.And(contentPredicate);
var boostQuery = PredicateBuilder.False<MySearchResultItem>();
boostQuery = boostQuery.Or(f => f["boostfield"] == "boostdata");
mainPredicate = mainPredicate.Or(boostQuery)
I think it could get you the results you need.
If you are simply looking to boost results based on an optional field, you can have your predicate builder as follows:
boostfield.contains("term") or field.contains("term")
And then increase the boost value in the standard fields for the field item itself. The order in which you build the predicate has a bearing on the results so make sure you check against the boost field first.

using listdata only and get from another model in Yii

can i just have listdata by itself? The list doesn't list anything, all I keep getting is "Array" as the return.
I have:
$awards= $model->findAll('uid='.$uid);
return CHtml::listData($awards, 'award_id', '$data->award->name');
try this code:
$awards= $model->findAll(array('condition'=>'uid ='.$uid)); // get records from table
return CHtml::listData($awards, 'award_id', 'award_name'); // third parameter should the array value. Most of the case we use to display in combo box option text.
If you are getting from another table, then declare a variable in your award model.
public $awrd_name;
Then you have to get records using relation in criteria.
Output will be :
array("1" => "award1", "2" => "award2", "3" => "award3");
refer this link : http://www.yiiframework.com/forum/index.php/topic/29837-show-two-table-fields-in-dropdownlist/