Getting null value when accessing fields from result in Searcher in Vespa - vespa

My Searcher is given below. When I hit search API then in my Searcher, I am getting null values when I tried to get fields of document. I am able to get id, relavance and source but not fields. Why is it so?Am I doing something wrong? Please help.
#Override
public Result search(Query query, Execution execution) {
// pass it down the chain to get a result
Result result = execution.search(query);
String title = result.hits().get(0).getField("title");
System.out.println(title);
// return the result up the chain
return result;
}
I am getting null value in title.

This is because results are initially surfaced without field data added (for performance).
Add
execution.fill(result);
before accessing fields (send the summary class to fill as second argument if you have multiple ones).

Use execution.fill(result) to fill the result before accessing fields. See also https://docs.vespa.ai/documentation/reference/inspecting-structured-data.html

Related

Why is my object not changing when I reassign properties in a forEach loop?

I am fetching an array of objects from an RX/JS call from an http backend. It returns an object which I am then trying to work with. I am making changes to this object using a for loop (in this example I am trying the .forEach because I have tried a number of different things and none of them seem to work.
When I run the code, I get a very weird problem. If I return the values of the properties, I get the new values (i.e. correctionQueued returns as true, etc.) but in the very next line, when I return the object, those same values are the same as the original (correctionQueued === false, etc.) HOWEVER, correctionStatus (which does not exist on the original object from http) sets just fine.
I don't understand how
array[index].correctionQueued can return true, but
array[index] returns an object with correctionQueued as false.
After the loop, the original array (checklistCopy) is identical to the object before the forEach loop, except the new property (correctionStatus) is now set, but all properties that I changed that were part of the original object remain as they were.
I have tried using a for of, for in, and .forEach. I have used the index to alter the original array, always the same result. Preexisting properties do not change, new properties are added. I have even tried working on a copy of the object in case there is something special about the object returned from rxjs, but to no avail.
checklistCopy.forEach((checklistItem, index, array) => {
if (checklistItem.crCode.isirName === correctionSetItem) {
array[index].correctionQueued = true;
array[index].correctionValue = mostRecentCorrection.correctionValue;
array[index].correctionStatus = mostRecentCorrection.status;
console.log(array[index].correctionQueued, array[index].correctionValue, array[index].correctionStatus);
console.log(array[index]);
}
}
);
I don't get an error, but I get..
Original object is:
correctionQueued: false;
correctionValue: JAAMES;
--
console.log(array[index].correctionQueued, array[index].correctionValue, array[index].correctionStatus);
true JAMES SENT
but when I print the whole object:
console.log(array[index]);
correctionQueued: false;
correctionValue: JAAMES;
correctionStatus: "SENT'; <-- This is set correctly but does not exist on original object.
console.log(array[index]) (at least in Chrome) just adds the object reference to the console. The values do not resolve until you expand it, so your console log statement is not actually capturing the values at that moment in time.
Change your console statement to: console.log(JSON.stringify(array[index])) and you should discover that the values are correct at the time the log statement runs.
The behavior you are seeing suggests that something is coming along later and changing the object properties back to the original value. Unless you show a more complete example, we can't help you find the culprit. But hopefully this answers the question about why your logs show what they show.
Your output doesn't make sense to me either but cleaning up your code may help you. Try this:
checklistCopy.forEach(checklistItem => {
checklistItem.correctionQueued = checklistItem.crCode.isirName === correctionSetItem;
if (checklistItem.correctionQueued) {
checklistItem.correctionValue = mostRecentCorrection.correctionValue;
checklistItem.correctionStatus = mostRecentCorrection.status;
console.log('checklistItem', checklistItem)
}
}
);

kotlin "contains" doesn't work as expected

I am working with a method which filters the preferences which match with the ids, I am using the contains method, but even though the values are the same, the contains is showing a false in each iteration. The method looks like:
private fun filterPreferencesByIds(context: MyPodCastPresenterContext): List<FanPreferences> {
return context.preferences?.filter {
context.ids.contains(it.id)
}
}
The values of the arrays are:
for the context.ids:
"B52594F5-80A4-4B18-B5E2-8F7B12E92958" and "3998EDE7-F84B-4F02-8E15-65F535080100"
And for the context.preferences:
But even though, when the first and the final ids have the same id value as the context.ids, the contains is false in the debug. I think it could be related with the types in the context.ids rows Json$JsonTextNode. Because when I did the same with numeric values hardcoded the compare is successful.
Any ideas?
Thanks!
If the type of FanPreferences.id is String and the type of context.ids list element is JsonTextNode, you won't find an element equal to the given id string, because it's not of String type.
Try mapping your context ids to the list of strings before filtering:
val ids = context.ids.map { it.toString() }.toSet()
return context.preferences?.filter {
ids.contains(it.id)
}
Note that calling toString() on JsonTextNode might be not the best way to get the string data from it. It's better to consult the API documentation of that class to find it out.

Can someone help me add a new column in Google cloud Search Index using Java

I tried adding a new column to an existing search index but it is throwing an error, the error as stated below:-
Field docname is present 0 times; expected 1
java.lang.IllegalArgumentException: Field docname is present 0 times; expected 1
I can see that the new column has been added to the search index but cannot retrieve the index.
By my observation i can see that the existing records in the index dont have the new column data and hence it is giving a this error, but the new records will be having this column values. Can anyone help me with this.
Upon having this problem myself today, I searched a bit in the documentation. It was a rather frustrating error as it didn't actually pin point where the problem was in my code.
It appears that when you use getOnlyField("something") on a Document (in this case on one of many returned from a search query), if that field does not actually exist yet in that specific document it throws the java.lang.IllegalArgumentException.
Because that can often be the case when you update an index with new columns, I'm using something like this to get around it:
public static Long getNumberField(ScoredDocument d, String name, Long defaultValue) {
try {
return d.getOnlyField(name).getNumber().longValue();
} catch (IllegalArgumentException e) {
return defaultValue;
}
}
Which is called in the search results code:
Long numberValue = SearchUtils.getNumberField(scoredDocument, "featuredOrder", -1L)
This allows me to catch that error and return a default value when it doesn't exist.
You can find the documentation here:
https://cloud.google.com/appengine/docs/java/javadoc/com/google/appengine/api/search/Document.html#getOnlyField-java.lang.String-

Using FindPagesWithCriteria in Episerver returns no results

i wonder if someone else has come accross this issue. I am trying to use FindPagesWithCriteria and i am creating my property criteria as like this:
PropertyCriteria dateCriteria = new PropertyCriteria();
dateCriteria.Condition = CompareCondition.GreaterThan;
dateCriteria.Name = "PageStopPublish";
dateCriteria.Type = PropertyDataType.Date;
dateCriteria.Value = DateTime.Now.ToString();
dateCriteria.Required = true;
so i am trying to find all the pages that are not expired. However, some pages may not have StopPublish property set in which case Datetime.MaxValue should be used. But in this particular case (no StopPublish value set) FindPagesWithCriteria will not return any results. Is there a reason for this or is it a bug? As a workaround, i am returning using PageTypeName criteria and then applying some additional filterin for returned PageDataCollection
FindPagesWithCriteria will only give you published pages (and pages that the current user have access to) so having StopPublish as a criteria is not necessary.
FindAllPagesWithCriteria will return all pages, including unpublished pages and pages the current user does not have access to.
EPiServer properties with an empty value are never stored in the database. If you access it from code, it will always be null.
To search for a null property using PropertyCriteria, set the IsNull property to true

MVC 4 return entries from database excluding specific items

I've been changing this call around for some time and can not quite get it to work. I am trying to return some records from a database and exclude items based on their ID numbers.
This is a database of quotes and when someone hides a quote it stores the quoteID in a cookie (required) and when returning to the site, The cookie.value is read.
I need to filter these IDs out of the return query and display the results in a view using WebGrid. I have the cookie part working. I retrieve the values (could be multiple) and split this into a list of strings. I then run a foreach loop ans parse the string to an integer and then try to remove quotes that I have retrieved from the database. Here is the code as I am using it...
// Filter on Cookie Value using tokenizer
string value = Request.Cookies.Get("hideCookie").Value;
List<string> values = value.Split(' ').ToList();
var quotes2 = db.Quotes.Include(q => q.QName);
foreach (var i in values)
{
int idv = int.Parse(i);
quotes2 = from q in quotes2 where q.QuoteID != idv select q;
}
return View(quotes2.ToList());
This throws an error "A specified Include path is not valid. The EntityType 'Exercise4.Models.Quote' does not declare a navigation property with the name 'QName'." (QName being an entry in the database record).
If I remove the ToList() in the return View(), quotes2 gets passed to the View but throws this error on the webGrid "A specified Include path is not valid. The EntityType 'Exercise4.Models.Quote' does not declare a navigation property with the name 'QName'."
I'm sure there is a much better way of doing this. Can you please point me in the correct direction so I can stop banging my head against my desk...

Resources