Question

I am trying to query records where ParentId = thread OR DataId = Thread. The query keeps timing out on me. Is there something wrong with the query below?

var Test = solr.Query(new SolrQueryByField("ParentId", Thread) ||
                     (new SolrQueryByField("DataId", Thread)));
Was it helpful?

Solution

I am not an expert in Solr.Net but I have used it for one project. I can only suggest you try couple of things.

First go to your SOLR Admin and try executing the query:

(ParentId:"Thread") OR (DataId:"Thread")

If you get any result back and its not timing out, you can use the same string in Solr.Net like:

string strQuery = "(ParentId:\"Thread\") OR (DataId:\"Thread\")"; 
// or use * for contains instead of double quotes
var query = new SolrQuery(strQuery);
SortOrder sortOrder = new SortOrder("ParentId");
var solrQueryResult = solr.Query(query, new QueryOptions
    {
        Rows = 100, //Max Rows returned
        Start = 0,
        OrderBy = new[] { sortOrder }, //If you want the ordered result
    });
 var list = solrQueryResult.ToList();//if you want list

OTHER TIPS

You can do this without concatenating strings manually:

ISolrOperations<User> solr = ServiceLocator.Current.GetInstance<ISolrOperations<User>>();
var users = solr.Query(new SolrQuery("age:20") || new SolrQuery("age:30"), options);

More info here: https://github.com/mausch/SolrNet/blob/master/Documentation/Querying.md

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top