MSSQL datetime to SOLR date using ColdFusion - sql-server

My query has a field CONTENTDISPLAYDATE and cfdump displays it as "2014-10-16 00:00:00.0". I add it to the SOLR collection using contentdisplaydate_dt="ContentDisplayDate" in my cfindex statement.
When I cfdump the resulting data from the cfsearch result, the field appears as "Thu Oct 16 00:00:00 EDT 2014" and sorting on it doesn't work. Using query of queries on the resultset and ordering by it also doesn't work. So looks like assigning it to a SOLR date field isn't working. Can anyone shed light on what I'm doing wrong? We're using the default version of SOLR that ships with CF 10.

The first thing to do would be to check to make sure that the field contentdisplaydate_dt is defined as a date field in Solr. You can do this by looking at the file schema.xml under this particular collection (often C:\ColdFusion9\collections\mycollection\conf\).
You can also confirm the content of contentdisplaydate_dt by querying the Solr index directly in your browser (using the Solr web service):
http://mysolrserver:8983/solr/myindex/select?q=searchterm&fl=contentdisplaydate‌​_dt
(The above URL will return XML data by default; if you prefer JSON then add &wt=json to the URL.)
My guess is that what is happening is that ColdFusion is trying to convert the Solr dates (which are always of the format yyyy-mm-ddThh:mm:ssZ) and the results aren't pretty. You have to do some manipulation in order to convert Solr dates to a date format recognized by CF.
Last, I would encourage you to use Solr's web service both to index and to search your data rather than using <cfindex> and <cfsearch>. Searching is especially easy with the Solr web service; just use <cfhttp> to call the web service and deserializeJSON() to process the data returned (assuming you're returning JSON instead of XML).

Related

SOLR Solarium can we use filter-queries with dismax-queries?

i just built a search form backed by solr, we are using the solarium library to construct our requests.
we built a "huge" collection of filterqueries like that one:
$query = $client->createQuery($client::QUERY_SELECT);
$query->setStart(0)->setRows(1000);
$query->addFilterQuery($query->createFilterQuery("foo")->setQuery("bar:true"));
$query->addFilterQuery($query->createFilterQuery("fo")->setQuery("ba:false"));
....
but we realized that the search just hits all the single fields we specify in the filterqueries, but we have to actually query multiple fields. while reading the docs i realized we could have been wrong, right? the correct approach would be to use disMax queries (in combination with facets?)? im wondering, can we use DisMax in combination with filterqueries to "expand" our search to multiple fields (with boosts) ? or do we have to actually rework everything?
im kinda missing the big picture to decide what the best/working solution would be
help is much appreciated
edit:
solr:
solr-spec 7.6.0
solarium:
solarium/solarium 6.0.1 PHP Solr client
You can give a query parser when giving the fq argument:
fq={!dismax qf="firstfield secondfield^5"}this is my query
The syntax is known as Local Parameters. Since dismax (or edismax which you should normally use now) doesn't have a identifier in front of it, it is implicitly parsed as the type.
If a local parameter value appears without a name, it is given the implicit name of "type". This allows short-form representation for the type of query parser to use when parsing a query string.
You'll have to make sure that Solarium doesn't escape the value you give to setQuery, but seeing as you're already giving a field:value combination, it doesn't seem to get escaped. Double check the Solr log to see exactly what query is being sent to Solr (or ask Solarium to give you the exact query string being sent if possible).

Spring Data Solr: Queries with "AND", "NOT" and "OR" not escaped or handled

We are using spring-data-solr, mainly using exact match/equals filter queries.
We have found that the values NOT, OR, and AND can be supplied, which are passed directly onto solr (without any pre-processing). This causes solr to error. For example, building a Criteria object like
Criteria.where("fuelType").is("AND")
Results in the following solr query
fq=fuelType:AND
We have found that if we call Solr directly with
fq=fuelType:"AND"
This would be fine, however, I can see that quotes are only added when there is whitespace in the value.
Is there something I am missing?
I still want to use the Standard Solr query parser if possible
The pull request for this has been merged,
https://jira.spring.io/browse/DATASOLR-437
https://github.com/spring-projects/spring-data-solr/pull/74

why in solr 1.4 passing a letter to a 'int' field results in exception?

I'm running lucene solr 1.4 on top of tomcat.
I have a field id defined with type int which is mapped to solr.TrieIntField.
When I do a solr query like ?q=id:a I get a NumberFormatException.
Is it possible to configure solr in such a way that it returns empty result set for above scenraio instead of throwing the exception?
Why do you have to have this as TrieIntField? Can you not use ? They are all sub classes of non tokekenized field (org.apache.solr.schema.FieldType).
Update: Based on your original question, as it is about id, i suggested to use string, as it makes no difference in that case. But if other fields use TrieIntField type the downside of using string for those fields is that your sorts and range queries may go string based and may be not desirable. In that case you need to prevent your orignal problem in client API or you need to handle them better by writing your own handler. Solr is doing correct thing by giving error as most applications would capure this error and respond to users with better user error message. If solr returns no results instead of error then it would be missleading.
Solr is written in Java so it is expected. You have to either filter out non-integer value from your client side (or API layer) or use String type as Arun suggested.

Solr 4.2.1 and SOLR-1604 : ComplexPhrase AND date range queries do not work together

I recently patched my Solr 4.2.1 with the ComplexPhrase query addon (https://issues.apache.org/jira/browse/SOLR-1604). When I issue a query such as :
my_text_field:"testin* compl*"~1 AND my_date_field:2013-12-12T04:58:53.732Z
I get results that contain the text query I issued and the date I issued in the my_date_field.
But when I do this:
my_text_field:"testin* compl*"~1 AND my_date_field:[2013-01-01T02:58:53.732Z TO 2013-12-12T04:58:53.732Z]
I get no results.
If I remove the complexphrase parser things go back to normal ( but I have no support for complex phrase queries ).
Ok after some time reading the lucene and solr code I figured it out.
This patch creates a Query Parser that extends the Lucene QueryParser. The Lucene QueryParser does not handle range queries other than Term Ranges ( simple strings in a way ). If one wants to specialize the behavior of the QueryParser, he must extract the field type and create the appropriate range query ( eg NumericRangeQuery for numbers, etc).

Get Latest N Documents from Solr

I have a standard Solr 3.6 index and am looking to get the latest N documents back (date ascending from indexing them).
This site was helpful but not exactly what I'm looking for.
I am looking to do something like this:
localhost:8080/solr/select/?q=greekbailout&wt=json; date asc
Basically, query whatever with json output and the latest N submitted documents to the index. Anybody run into this before?
Use &sort=date asc for pure sorting and this for boosting newer documents.
solr query using date field with N documents returned in results
localhost:8080/solr/select/?q=greekbailout&wt=json&sort=date asc&rows=N
default schema of solr has a field called timestamp, which stores time at which a particular document is created or modified, so if your date field doesn't quite store this and this is your requirement, you can use timestamp.. just replace date with timestamp
In your Solr URL just apend &sort=<field>+<asc/desc>. Also your field should be indexed and not multivalued.
You can also sort on multiple fields.
&sort=<field name>+<direction>[,<field name>+<direction>]...
http://wiki.apache.org/solr/CommonQueryParameters#sort

Resources