Spellchecking w SolrNet 400 Bad Request using colon : in spellcheck query - solr

I'm using SolrNet and when I pass a query that has a colon in it, I receive this error:
Apache Tomcat/6.0.32 - Error report
The request sent by the client was syntactically incorrect (null).
The code sample looks like this:
var results = SolrOps.Query(request.Query, new QueryOptions
{
SpellCheck = new SolrNet.Commands.Parameters.SpellCheckingParameters
{
Collate = true,
Build = true,
Query = "test:"
}
});
Am I required to strip the colon manually, or is there some option I can set (either in SOLR or SOLRNet) to fix this?

I am thinking that spellchecking does not support special characters and you will need to filter/strip those out of the query term(s) prior to submitting the request to Solr via SolrNet.

Related

Apache Camel route, pull a value from a BSON document to put in an http connection string

I'm pulling a document from a MongoDB and want to take the value of startTime and add it as a connection parameter to an http url string.
The document looks like this:
Document{{_id=6110593a2d79803d4ebf2b83, startTime=1585009140000}}
I'm using projection to get only the field I need. I can log the value using jsonpath. But how to I get the value in a way I can cleanly add it to the http url?
from("timer:PingTimer?fixedRate=true&period=15000")
.setHeader(MongoDbConstants.SORT_BY).constant(Sorts.descending("startTime"))
.setHeader(MongoDbConstants.FIELDS_PROJECTION).constant(Projections.include("startTime"))
.setBody().constant("{}")
.to("mongodb:mongo?database={{spring.data.mongodb.database}}&collection=one_min&operation=findOneByQuery")
.log("Body ${body}")
.toD("https://this.that/api/markets/USD?resolution=60&start_time="
//How do I get the value of startTime in here?
)
.setBody().jsonpath("$.startTime") // This gets the value
;
[Edit]
Is this advisable?
.setHeader("test").jsonpath("$.startTime")
.toD("https://this.that/api/markets/USD?resolution=60&start_time=" + "${headers.test}")

Replace entire document in Bulk Operation Spring MongoDB

I am using Spring Boot Version 2.1.0 and mongo driver version 3.8.2. I am not able to replace the entire document during bulk update operation.
It was working fine before upgrading to Spring Boot version 2.1.0. I was using ops.find().replaceOne() in spring boot 1.5.9
I tried BulkOps.updateOne.. But it is throwing Invalid Bson Name _id.
I tried dbObject.remove("_id"); But still getting the error with other fields.
BulkOperations ops = mongoOperations.bulkOps(BulkOperations.BulkMode.UNORDERED, A.class);
list.forEach(item -> {
Document dbObject = new Document();
converter.write(item, dbObject);
ops.updateOne(query(where("_id").is(item.getId())),Update.fromDocument(dbObject));
});
ops.execute();
Expected -- it should replace the entire document matching the ID.
final BulkOperations bulkOperations =
mongoTemplate.bulkOps(BulkOperations.BulkMode.ORDERED,A.class, A);
final Query query = new Query();
query.addCriteria(Criteria.where("_id").is(A.getId()));
bulkOperations.replaceOne(query,A);
bulkOperations.execute();

Using `qt` parameter in solr

I am using solr-php-client and it its default request-handler is select there is no way to change it unless I change the code itself. however, there is the parameter qt. I updated solrconfig to include <requestDispatcher handleSelect="true" > and I tried to use request handler name with or without / in solrconfig as well as in the url with qt parameter.
This link is working:solr_server_port_index/custom?q=
While this is not: solr_server_port_index/select?qt=custom&q= neither this solr_server_port_index/select?qt=/custom&q=
what am I missing here?
Solr uses the qt parameter to determine which Query Handler should be used to process the request. Valid values are any of the names specified by declarations in solrconfig.xml.
if we won't specify qt parameter then there must be a request handler in solrConfig.xml for a given request.
my experiments with solr 1.4 with qt parameter is mentioned below
<requestHandler name="/ana" class="solr.DisMaxRequestHandler" >
......
</requestHandler>
http://url:8081/solr/select?wt=xml&q=questionDetail:question&start=0&rows=10&qt=/ana
working fine
http://url:8081/solr/ana?wt=xml&q=questionDetail:question&start=0&rows=10
working fine
http://anaplatha.99.jsb9.net:8081/solr/select?wt=xml&q=questionDetail:question&start=0&rows=10&qt=\ana
error : HTTP Status 400 - unknown handler: \ana(this error I am getting for any value of qt which is != /ana)
references ::
https://wiki.apache.org/solr/CoreQueryParameters
https://issues.apache.org/jira/browse/SOLR-3161
To work around the missing configurability of solr-php-client (I created issue #6 to track this), you can extend the Service class and override the _constructUrl method to detect calls to select - and replace it with your own request handler. Modify this example to take the request handler name as custom ->setRequestHandler or however you want to fix it:
class Custom_RequestHandler_Solr extends Apache_Solr_Service {
public function _constructUrl($servlet, $params = []) {
if ($servlet == 'select') {
$servlet = 'mycustomrequesthandler';
}
return parent::_constructUrl($servlet, $params);
}
}

Solr 4.3.1 Data-Import command

I'm currently using Solr 4.3.1. i have configured dih for my solr. i would like to do a full import through command prompt. I know the url will be something like this http://localhost:8983/solr/corename/dataimport?command=full-import&clean=true&commit=true is there any method i can do this without using curl ?
Thanks
Edit
string Text = "http://localhost:8983/solr/Latest_TextBox/dataimport?command=full-import&clean=true&commit=true";
var wc = new WebClient();
var Import = wc.DownloadString(Text);
Currently using the above code
Call it like a normal REST url that's it !! I am using it in my application for importing and indexing data from my Local drive and it just works fine ! :) . Use HttpURLConnection to make a request and capture response to see whether it was successful or not . You don't need any specific API to do that . This is a sample code to make a GET request correctly in C# .Try data import handler url with this, it may work !
Console.WriteLine("Making API Call...");
using (var client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }))
{
client.BaseAddress = new Uri("https://api.stackexchange.com/2.2/");
HttpResponseMessage response = client.GetAsync("answers?order=desc&sort=activity&site=stackoverflow").Result;
response.EnsureSuccessStatusCode();
string result = response.Content.ReadAsStringAsync().Result;
Console.WriteLine("Result: " + result);
}
Console.ReadLine();
}
}
}
You'll have to call the URL in some way - Solr only operates through a REST API. There is no command line API (the command line tools available just talk to the API). So use your preferred way to talk to a HTTP endpoint, that being curl, wget, GET or what's available for your programming language of choice.
The bundled solrCli application does not have any existing command for triggering a full-import as far as I were able to see (which would just talk to the REST API by calling the URL you've already referenced).

Make a solr query from Geotools through geoserver

I come here because I am searching (like the title mentionned) to do a query from geotools (through geoserver) to get feature from a solr index.
To be more precise :
I saw on geoserver user manual that i can do query on solr like this in http :
http://localhost:8080/geoserver/wfs?service=WFS&version=1.1.0&request=GetFeature
&typeName=mySolrLayer
&format="xxx"
&viewparams=q:"mySolrQuery"
The important part on this URL is the viewparams that I want to use directly from geotools.
I have already test this case (this is a part of my code):
url = new URL(
"http://localhost:8080/geoserver/wfs?request=GetCapabilities&VERSION=1.1.0";
);
Map<String, String> param = new HashMap();
params.put(WFSDataStoreFactory.URL.key, url);
param.put("viewparams","q:myquery");
Hints hints = new Hints();
hints.put(Hints.VIRTUAL_TABLE_PARAMETERS, viewParams);
query.setHints(hints);
...
featureSource.getFeatures(query);
But here, it seems to doesn't work, the url send to geoserver is a normal "GET FEATURE" request without the viewparams parameter.
I tried this with geotools-12.2 ; geotools-13.2 and geotools-15-SNAPSHOT but I didn't succeed to pass the query, geoserver send me all the feature in my database and doesn't take "viewparams" as a param.
I need to do it like this because actually the query come from another program and I would easily communicate this query to another part of the project...
If someone can help me ?
There doesn't currently seem to be a way to do this in the GeoTool's WFSDatastore implementations as the GetFeature request is constructed from the URL provided by the getCapabilities document. This is as the standard requires but it may be worth making a feature enhancement request to allow clients to override this string (as QGIS does for example) which would let you specify the additional parameter in your base URL which would then be passed to the server as you need.
Unfortunately the WFS module lives in Unsupported land at present so unless you have resources to work on this issue yourself and can provide a PR to implement it there is not a great chance of it being implemented.

Resources