NetSuite - Search customers by complex query - c#

I am trying to search customers who contain these fields : email or firstName or lastName or id.
must be an OR condition between of them.
for example
var freeText = "shomeone#gmai";
var customers = SearchForCustomersWhoContainsThisData(freeText)
how can i build this query in c#?
public List<Customer> SearchForCustomersWhoContainsThisData(string search_text)
{
CustomerSearch custSearch = new CustomerSearch();
SearchStringField searchField = new SearchStringField();
searchField.#operator = SearchStringFieldOperator.contains;
searchField.operatorSpecified = true;
searchField.searchValue = search_text;
CustomerSearchBasic custBasic1 = new CustomerSearchBasic();
custBasic1.firstName = searchField;
CustomerSearchBasic custBasic2 = new CustomerSearchBasic();
custBasic2.lastName = searchField;
custSearch.basic = custBasic1;
//custSearch.basic = custBasic2; how to add this with or between
// Search for the customer entity who contains this text
SearchResult response = _crmNetSuitService.search(custSearch);
var searchResults = response.recordList.Select(t => (Customer)t).ToList();
return searchResults;
}
I expect to find customers who one of these fields contains this search-text:
email, fName, lName, Id.

As per NetSuite SuiteAnswers id 31408
Web Services > Search > How to set a field filter for one value OR another value
Currently, expressions are not supported via Web Services searches.
In order to Search where a field is one value or another. It is necessary to submit two search requests, then merge the results in the application code.

Related

ASP.NET Core Linq query for lists

I have this query that was recently changed to allow searches using lists. However, the logic doesn't seem correct. My initial search logic was as follows:
data = data.where(u=>u.location.contains(FilterInput.RepositoryName)).ToList();
This worked for individual inputs and the logic made sense. In the data result, check if location field contains the Input variable
However in order to handle inputs that are lists, I had to change it to the bottom code which is in this Input list, check if the it contains the location field.
The database outputs data as follows:
Output = {arhde, brhje, ckio}
That means my list input is a small section of what the database contains.
FilterInput.RepositoryName = {a,b,c}
data = (from item in dbContext.Documents
join id in initialData
on item.Id equals id.DocumentId
select new DocumentsListViewModel
{
Id = item.Id,
Name = item.Name,
ApplicationName = item.ApplicationName,
ApplicationSecretKey = item.ApplicationSecretKey,
Link = item.Link,
Location = item.Location,
FileType = item.FileType,
CreatedOn = item.CreatedOn
}).ToList();
if (FilterInput.RepositoryName.Count>0)
{
data = data.Where(u => FilterInput.RepositoryName.Contains(u.Location)).ToList();
}
I don't know if its possible to change this logic to use the first one but accomodate lists as well?

DynamoDB query returns zero results

I'm trying to query a DynamoDB table to find a product based on it's url.
The table has three fields: Title, Description & Url.
var credentials = new BasicAWSCredentials(awsDBLogins.AccessKey, awsDBLogins.SecretKey);
var client = new AmazonDynamoDBClient(credentials, RegionEndpoint.USEast2);
var context = new DynamoDBContext(client);
Table table = Table.LoadTable(client, "Products");
With the above code i'm able to connect to the table. I then execute the below query which does not return any error's however the list of results is empty. I am expecting one result to be returned where the Url matches "test".
var productUrl = "test"
QueryOperationConfig config = new QueryOperationConfig()
{
Filter = new QueryFilter(productUrl, QueryOperator.Equal, "Url"),
AttributesToGet = new List<string>
{ "Title", "Description", "Url" },
ConsistentRead = true,
};
var ProductItem = table.Query(config);
While this does not work in the code, I'm able to find the entry in the database when looking list of item's from the AWS web portal / console so I know that the entry exists.
Am I making a mistake in my filter?
I think the hash key name and value should be reversed. First parameter is the key name and third parameter is the value.
Filter = new QueryFilter("Url", QueryOperator.Equal, productUrl)

Best way to group a query result by a column in SQL Server or using C# code

I am working on a search form in C# and I have two tables which users can search in them, one of them is property table and another one is users. As you know each user can have more than one property. So if I want to find users that have a property with color=red and price X when I run query it gives me many users and some of them is duplicated I mean the the phone number of users are same. So as the result of a query that user does I have a result such as this
User.name|user.phone|product.color|product.price|product.id
-----------------------------------------------------------
a |9828393999|red |XX |yt3
a |9828393999|red |XX |y23
b |9828393994|red |XX |3t3
b |9828393994|red |XX |4t3
This is a result of query that user performs..How I can get only phone numbers and name? I want something like this
User.name|user.phone|product.color|product.price|product.id
-----------------------------------------------------------
a |9828393999|red |XX |y23
b |9828393994|red |XX |4t3
Here is a sample query that I get from user
select
u.Name, u.Family, u.OBJECTID, u.phone,
p.number, p.Energy, p.Area, p.contex, p.title
from
[dbo].[user] as u, [dbo].[PROPERTY] as p
where
u.OBJECTID = p.owner_ID and [contex] = 0 and [title] = 2
No matters product.id, I just want the phone numbers.. So what is best method to do it?
Can I perform such thing in SQL Server? Or I must use codes?
One way that I can do is loop among data and get phone numbers. But I think it is some how not a good method..Can you help me find a good solution for this?
Thank you very much
Here's what I do for this type of thing...
Step 1) Create a model of your class...
public class MyModel {
public string UserName {get;set;}
public string UserPhone {get;set;}
public string ProductColor {get;set;}
public string ProductPrice {get;set;}
public string ProductID {get;set;}
}
Then I use Enitity Framework to project the results into that model like this.
using(var db = new MyEntities(){
string Query = "Select XYZ from Tablea,TableB where something=#parm";
SqlParameter[] parms = {new SqlParameter{name = "parm" value="somevalue");
var stuff = db.Database.SQLQuery<MyModel>(query, parms.ToArray());
return stuff.ToList();
}
Stuff will contain IEnumerable
Now you can use LINQ to filter what ever you want.
var grp = stuff.GroupBy(p=>p.UserPhone);
var justPhoneNumbers = stuff.Where(p=>p.ProductColor=="Red").Select(p=>p.UserPhone).ToList();
var filtered = stuff.Where(p=>p.ProductColor=="Red").ToList();
var filtered2 = stuff.Where(p=>p.ProductColor=="Red");
filtered2= filtered2.Where(p=>p.UserName == "Jones");
var finallist = filtered2.ToList();
Then just bind the results to the view and you're all set.

Display all elements in array from a response

Ok I have a confusing question (I think) in regards to request and response values.
I created a request to search for Customers within a database based on the company name. Here is the code:
//Search through customers
public void ArrangeRequest()
{
_request = new CustomerSearchRequest();
_request.Company = "NewCustomers Inc";
}
Here is customer info before it is requested and given values:
//Customer Info
_request.Customer = new CustomerInfo
{
Company = "NewCustomers Inc. ",
CustStatus = Status,
CustID = custid,
Fax = "(855) 555-6956",
Phone = "(568) 895-6954",
ProviderId = 56958,
TechContact = _techcontact,
TimeZoneInfoID = "Central Standard Time",
};
This request works and when I debug I get the message that 52 customers were found. Now, each of those customers has a unique customer ID that was created when they were. When I debug I am able to see all the information for the customers including their customer ID. My problem is I am trying to output all those values to a text file. The problem is the customer ID's are in an array with all the other information in: CustomerInfo[]. Now I am able to output each individual value in the array by saying CustomerInfo[1] or CustomerInfo[2], but I want to be able to make the search and output all the values in the array without having to call each individual value.
I want this so that if I wanted to search for another company and it has 1000 results then I won't have to call each one obviously.
edited based on OPs comments:
foreach(var customer in _response.Customers)
{
Console.WriteLine(customer.CustID);
}

Lucene search not working

I have a function which searches some articles in the Sitecore content items and give me the value. So far I have build up my indexes and it is showing in my IndexViewer. But the return of the function is 0. I looked up this link: http://sitecoregadgets.blogspot.com/2009/11/working-with-lucene-search-index-in_25.html for more information.
protected IEnumerable<Item> ShowHomePageNews(int numOfArticles, string stringofCountries)
{
List<Item> items = new List<Item>();
Sitecore.Search.Index indx = SearchManager.GetIndex("newsArticles");
using (IndexSearchContext searchContext = indx.CreateSearchContext())
{
var db = Sitecore.Context.Database;
CombinedQuery query = new CombinedQuery();
QueryBase catQuery = new FieldQuery("countries", stringofCountries); //FieldName, FieldValue.
SearchHits results = searchContext.Search(catQuery); //Searching the content items by fields.
SearchResultCollection result = results.FetchResults(0, numOfArticles);
foreach (SearchResult i in result)
{
items = result
.Where(r => !r.Title.StartsWith("*"))
.Select(r => db.GetItem(new Sitecore.Data.ItemUri(r.Url).ToDataUri()))
.ToList();
//Lucene.Net.Documents.Field url = i.Document.GetField("_url");
//Sitecore.Data.ItemUri itemUri = new Sitecore.Data.ItemUri(url.StringValue());
//Sitecore.Data.Items.Item item = Sitecore.Context.Database.GetItem(itemUri.ToDataUri());
//items.Add(item);
}
}
return items;
}
Over here the result is 0. What I am doing wrond here?
This is the snapshot of what I am seeing in my IndexViewer:
EDIT:
I am passing a "NZ" in the 'catQuery' and I am getting the result back. Because in my index viewer I am seeing the Field Name = _name, which contains NZ in it. I got this part. However, I want my every field to be indexed. I am seeing only 3 fields in my IndexViewer: _url, _group & _name.
So your countries should be tokenized by the indexer. As a multilist, they will be tokenized by GUID. Searching for a single country by GUID with your code above should work. However, if you want to search for multiple countries, where any of the passed in countries can trigger a match, you need to structure your query differently.
CombinedQuery query = new CombinedQuery();
//apply other filters here to query if need be
//and country filter by creating a new clause (combinedquery) and "ORing" within it (QueryOccurance.Should)
CombinedQuery query3 = new CombinedQuery();
//here you would actually iterate over your country list
query3.Add(new FieldQuery("countries", country1GUID), QueryOccurance.Should);
query3.Add(new FieldQuery("countries", country2GUID), QueryOccurance.Should);
query.Add(query3, QueryOccurance.Must);

Categories

Resources