how to use solr directly in sunspot - solr

I am using sunspot for ruby on rails and I need to try a solr query.
How can I run a solr query directly in sunspot?
The query is the following:
search(people, q="*:*", qt="/export", fl="personId,name", sort="personId asc"),
search(pets, q="type:cat", qt="/export", fl="personId,petName", sort="personId asc"),
on="personId"
)

Related

DisMax query parser is not running

Environment- solr-8.9.0
Movies data in a form of a .csv file has been indexed in apache solr.
Movies data
name,directed_by,genre,type,id,initial_release_date
.45,Gary Lennon,Black comedy|Thriller|Psychological thriller|Indie film|Action Film|Crime Thriller|Crime Fiction|Drama,,/en/45_2006,2006-11-30
9,Shane Acker,Computer Animation|Animation|Apocalyptic and post-apocalyptic fiction|Science Fiction|Short Film|Thriller|Fantasy,,/en/9_2005,2005-04-21
Bomb the System,Adam Bhala Lough,Crime Fiction|Indie film|Coming of age|Drama,,/en/bomb_the_system,
movie_name,Adam Bhala,Animation|Indie film|Coming of age|Drama,,/en/bomb_the_system,
The DisMax Query Parser has been run over the field 'directed_by'. 'directed_by' field is mapped as a 'text_general' field-type in managed-schema.
I have run the following query over solr
curl -G http://localhost:8983/solr/testCore1/select --data-urlencode "q=directed_by:'Adam Bhala Lough~'" --data-urlencode "defType=dismax" --data-urlencode "mm=2"
but the above query is giving 0 'numFound' in response.
I expect the following field to match:
Adam Bhala
Adam Bhala Lough
I expect the following field not to match:
Adam Gary Lennon
Although data is indexed in solr. I have cross-checked this by running the following query without disMax query parser and it is giving responses.
curl -G http://localhost:8983/solr/testCore1/select --data-urlencode "q=directed_by:'Adam Bhala Lough~'"
Why dismax query parser is not running as it should be? I understand that mm(Minimum Should Match) Parameter===> defines the minimum number of clauses that must match.
I have spent hours to solve this. However, I cannot seem to find anything that holds my hand.
Could someone help me find the missing piece?
Reference
https://solr.apache.org/guide/8_9/the-dismax-query-parser.html
How to use disMax query parser in solr
You need to use the qf (query fields) parameter to specify in which field(s) the search should be performed, along with (optionally) a boost factor used to increase or decrease that particular field’s importance in the query (defaults to 1) :
q=Adam Bhala Lough~
qf=directed_by
Or, use edismax query parser instead of dismax, so that the standard query syntax you were using (directed_by:'Adam Bhala Lough~') can work as intended.

SOLR query runs OK only on 1 node out of the 3 nodes with SOLR installed

Here's our problem. We're runnig DSE Enterprise 4.8 with the following configuration:
6 servers with Cassandra
on 3 of them Spark is installes (DSE Analytics)
on the orher 3 SOLR is installed (DSE Search)
We want to do "query stats" with SOLR on a table using and excluding certain filter queries.
When we try to execute a simple query like this:
/select?q=*:*&wt=json&indent=true&fq={!tag=fq1}test:100&stats=true&stats.field={!ex=fq1}test&rows=1
it runs OK only on 1 node out of the 3 with SOLR installed.
For the other 2 nodes we get this exception:
{
"responseHeader":{
"status":400,
"QTime":2},
"error":{
"msg":"undefined field: \"{!ex=fq1}test\"",
"code":400},
"params":"q=*:*&indent=true&stats=true&fq={!tag%3Dfq1}test:100&rows=1&wt=json&stats.field={!ex%3Dfq1}test"}
Could you help us identify the reason of the "undefined field" exception when using exluding filter queries inside the stats.field parameter.
Also it would help us to use only a subset of the stats functions ( for example only count ) :
stats.field={!count=true}test
But these types of parameters seem to be ignored and the whole set of stats functions are computed...
Many Thanks

Syntax for Solr Query with Cassandra Datastax integration

I'm trying to use DataStax Cassandra/Solr integration to do a facet query with both pivot facets and interval facets
My query look like this:
select * from data where solr_query='{"facet":{"limit":5,"pivot":"event_type,key","interval":"past_visits","f.past_visits.facet.interval.set":["{!key=visit_13_month}[NOW-13MONTH/MONTH,NOW]","{!key=visit_1_month}[NOW-1MONTH/DAY,NOW]"]},"q":"*:*"}']
The error that I am getting back seems to show that the required parameter is not being set (but it is)
08:30:38.244 [New I/O worker #4] WARN c.d.driver.core.RequestHandler - /10.239.133.151:9042 replied with server error (Missing required parameter: f.past_visits.facet.interval.set (or default: facet.interval.set)), trying next host.
When i run an equivalent query directly to Solr (using query params), it works as expected.
/data/select?q=*:*&facet=true&facet.pivot=event_type,key&facet.limit=5&facet.interval=past_visits&f.past_visits.facet.interval.set=%7B!key=visit_13_month%7D[NOW-13MONTH/MONTH,NOW]&f.past_visits.facet.interval.set=%7B!key=visit_1_month%7D[NOW-1MONTH/DAY,NOW]"
I'm trying to follow the Datastax documentation at this link:
http://docs.datastax.com/en/datastax_enterprise/4.8/datastax_enterprise/srch/srchJSON.html
There seems to be something wrong with the way that I am creating the JSON for the Datastax Solr query, but I do not see what I should change.
We don't currently support facet intervals via CQL. Anyway, you don't need to repeat "facet", so it should eventually be something like the following:
select * from data where solr_query='{"facet" {"limit":5,"pivot":"event_type,key","interval":"past_visits","f.past_visits.interval.set":["{!key=visit_13_month}[NOW-13MONTH/MONTH,NOW]","{!key=visit_1_month}[NOW-1MONTH/DAY,NOW]"]},"q":"*:*"}']

Not use wildcard when query solr string field value

My question is I found when I use wildcard in solr query, it will be very slow. So I don't want to use the wildcard(*) query, for example, I want to search the mail address (gosling.abc#gmail.com), if I input 'abc' keywords, my q parameter maybe like q:abc
How should I do with this condition?
I am newbie in solr, can anyone help me?
(Currently, I have 10,937,547 document in my solr cloud. My solr version is 4.1)

Solr not searching (Very basic example)

Solr version :
4.2.1
Objective:
I am trying to get a very simplistic Solr example off the ground
So far:
Installed solr
Was able to run the example\tutorial successfully http://lucene.apache.org/solr/4_2_1/tutorial.html
Next:
Now I am trying to create my own schema
I have created a schema : http://pastebin.com/vj4ATa8d
And a Test Doc:http://pastebin.com/7fvZ5GTQ
I have added the doc to Solr using the command
java -jar post.jar testdoc.xml
What’s working:
In Solr Admin- I can see the schema
I can see one document uploaded
I can go to Admin console and query as follows:
Specify q as “:”. This works- shows the document
http://localhost:8983/solr/collection2/select?q=*%3A*&wt=xml&indent=true
What does not work:
If I give q as Nashua- I see no results
This is the default search field
Other attributes didn't work either
http://localhost:8983/solr/collection2/select?q=Nashua&wt=xml&indent=true
The debug response http://pastebin.com/fTneyEba
You need to either copy your fields into the default search field (in this case text) or qualify your query with the field you want to search against:
.../select?q=city:Nashua&wt=xml&indent=true
Things to read up on:
Default Search Field
Copy Fields
Both are documented here:
https://wiki.apache.org/solr/SchemaXml

Resources