How to query Coveo rest API to lookup for a value in more than single field? - coveo

I have the following records in Coveo,
Record 1
#firstname = "Steve"
#lastname = "Jobs"
#fullname = "Steve Jobs"
Record 2
#firstname = "Jose"
#lastname = "Steve"
#fullname = "Jose Steve"
Record 3
#firstname = "Joe"
#lastname = "Brian"
#fullname = "Joe Brain"
I would like to query to get both "Steve Jobs" & "Jose Steve".
Should the query be like this (#lastname = "steve" or #firstname = "steve")???
or Do I have any other option???

In the Coveo query syntax, the "=" operator is the "contains keyword" operator. This means you can just use your #fullname field like this:
#fullname = "steve"
It will give the same results as the query you suggested:
#lastname = "steve" OR #firstname = "steve"
Note that Boolean operators need to be in uppercase in the Coveo query syntax.
More information about the Coveo query syntax and operators:
https://onlinehelp.coveo.com/en/ces/7.0/user/coveo_query_syntax_reference.htm
https://onlinehelp.coveo.com/en/ces/7.0/user/search_query_examples.htm
https://onlinehelp.coveo.com/en/ces/7.0/user/search_prefix_and_operators.htm
https://onlinehelp.coveo.com/en/ces/7.0/user/advanced_field_queries.htm

Related

HQL query returing null value on use of like operator for search

query = genericDAOImpl.getHibernateSession().createQuery("select t from ticket t where createdBy=:user and t.subject like concat("%", :summary, "%")
.setParameter("user", userId)
.setParameter("summary", inputBean.getSummary);
this is my query when I search for some values it returns the proper output but when I give null value for the search field it returns empty list actually it should return all the values when the search field is empty
You should just use a plain named placeholder for the predicate of the LIKE expression, and then bind the wildcard string from the Java side:
String sql = "select t from ticket t where createdBy = :user and t.subject like :summary";
query = genericDAOImpl.getHibernateSession().createQuery(sql);
query.setParameter("user", userId);
query.setParameter("summary", "%" + inputBean.getSummary + "%");

Is it possible to put a subquery inside the FROM statement in my HQL Querys?

Here is my query.
SELECT letter
FROM
Letter AS letter,
(evaluateDisplayName) AS displayName
WHERE
letter.id =: someID
AND displayName =: someDisplayName
// AND etc etc...
The Subquery in this part:
(Do some subquery here) AS displayName
I don't know how to form. But the logic is something like this:
private String evaluateDisplayName(Letter letter) {
def username = letter?.sender?.username
def lastName = letter?.sender?.lastName
def emailAddress = letter?.sender?.emailAddress
return username ?: lastName ?: emailAddress
}
How to turn this into a subquery?
You don't need a subquery, the logic of evaluateDisplayName seems to be the same of the coalesce function: return the first not null value. Try with this:
SELECT letter
FROM
Letter AS letter LEFT JOIN letter.sender AS sender
WHERE
letter.id = :someID
AND COALESCE(sender.username, sender.lastName, sender.emailAddress) = :someDisplayName
// AND etc etc...

Is there a way to get all Contacts without specific criteria?

Using the Infusionsoft gem, is there a way to get all Contacts through the Infusionsoft API without a specific criteria?
Simply use the wildcard as a query parameter for the Id field:
query = {"Id" => "%"}
selected_fields = %w(Id FirstName LastName ...)
data = Infusionsoft.data_query("Contacts", 1000, 0 , query, selected_fields)
The API will return an array of hashes, each one representing the contact with the selected fields as keys.
As per yuga's comment, if you have more than 1000 contacts, you will need to add a loop for data pagination:
contacts = []
i = 0
query = {"Id" => "%"}
selected_fields = %w(Id FirstName LastName ...)
loop do
data = Infusionsoft.data_query("Contacts", 1000, i , query, selected_fields)
break if data.empty?
contacts.concat(data)
i += 1
end

How do I get a count of values by month in linq to sql?

I have a table of feedback scores, which essentially contains a date field and a "score" field (which may be "happy", "neutral" or "sad").
I want to return a query which gives me the count of each score by month, like this:
However, my query isn't grouping correctly - I'm basically getting three rows for each month (one row for "happy", one for "neutral" and one for "sad", like this:
How do I aggregate the data together?
My query at the moment is this:
var monthlyScore = from f in db.tl_feedbacks
group f by new { month = f.timestamp.Month, year = f.timestamp.Year, score = f.tl_feedback_score.score } into g
select new
{
dt = string.Format("{0}/{1}", g.Key.month, g.Key.year),
happyCount = g.Where(x => x.tl_feedback_score.score == "happy").Count(),
neutralCount = g.Where(x => x.tl_feedback_score.score == "neutral").Count(),
sadCount = g.Where(x => x.tl_feedback_score.score == "sad").Count(),
total = g.Count()
};
Remove , score = f.tl_feedback_score.score from your grouping.

Replace Linq to Entity value in Projection

I want to relace a value retrieved from a L2E projection to an expanded string.
The table contains a column called Status which can have a value "0" or "1" and in my L2E I have
var trans = from t in db.Donation
select new DonationBO()
{
Status = t.Status
};
What I want is to return either of the strings "Pending" or "Committed" instead of "0" or "1".
How can I do this here?
If Status is a string you could simply do:
var trans = from t in db.Donation
select new DonationBO()
{
Status = t.Status == "0" ? "Pending" : "Committed"
};

Resources