How to use multiple setQuery on solr?
i want to search name="din" and staus="active" and email="din"
am using like this
if(isset($_GET["name"]) && $_GET["name"]!=""){
$query->setQuery('name:*'.$_GET["name"].'*');
}
if(isset($_GET["email"]) && $_GET["email"]!=""){
$query->setQuery('email:*'.$_GET["email"].'*');
}
if(isset($_GET["role"]) && $_GET["role"]!=""){
$query->setQuery('role:*'.$_GET["role"].'*');
}
if(isset($_GET["status"]) && $_GET["status"]!=""){
$query->setQuery('status:'.$_GET["status"]);
}
But its not giving proper response
let me know how to use ?
->setQuery() sets the query. If you want to set several conditions, you'll have to provide all of them. Also remember that any $_GET variable can contain spaces and similar values, and should be properly escaped.
You can build a query by keeping each term by itself, before merging it into a single query string at the end:
$queries = array();
if (!empty(if($_GET["name"])) {
// add proper escaping here, so you don't escape * as well.
$queries[] = 'name:*'.$_GET["name"].'*';
}
// you probably want to check that there actually is any queries here as well
$query->setQuery(join(" AND ", $queries));
Related
I'm having an issue when using azure search for the following example data set: abc-123-456, abc-123-457, abc-123-458, etc
When making the search for abc-123-456, I'd expected to only return one results but instead getting all results containing abc-123-...
Is there some setting or way to change this behavior?
Current search settings:
TheSearchIndex.TokenFilters.Add(new EdgeNGramTokenFilter("frontEdgeNGram")
{
Side = EdgeNGramTokenFilterSide.Front,
MinGram = 3,
MaxGram = 20
});
TheSearchIndex.Analyzers.Add(new CustomAnalyzer("FrontEdgeNGram", LexicalTokenizerName.Whitespace)
{
TokenFilters =
{
TokenFilterName.Lowercase,
new TokenFilterName("frontEdgeNGram"),
TokenFilterName.Classic,
TokenFilterName.AsciiFolding
}
});
SearchOptions UsersSearchOptions = new SearchOptions
{
QueryType = SearchQueryType.Simple,
SearchMode = SearchMode.All,
};
Using azure.search.documents ver 11.1.1
Edit: Search with abc-123-456* with the asterisk gives me the one result as expected. How to get this behavior working as default?
Just to add to this..
The portal version is 2020-06-30
The sdk version we use is azure.search.documents ver 11.1.1
abc-123-456 does NOT work as expected
"abc-123-456" does NOT work as expected
"abc-123-456"* does NOT work
"abc-123-456*" does NOT work
If we append an asterisks to the end of the search text and it is not within a phrase .. it works as expected.
IE:
abc-123-456* works as expected.
(abc-123-456* | abc-123-457* ) works as expected.
Why is the asterisks required? How can we make this work within a phrase?
This is expected behavior when using the EdgeNGramTokenFilter inside the custom analyzer configuration. The text “abc-123-456” is broken into smaller tokens like “abc”, “abc-1”, “abc-12”, “abc-123”….”abc-123-456”. Check out the Analyzer API for the full list of tokens generated by a particular analyzer.
For a query - abc-123, if the default analyzer is being used, the query terms will be abc and 123 and will match all the documents that contain these terms.
The prefix query on the other hand is not analyzed and looks for documents that contain the prefix as is “abc-123”. A prefix search bypasses full-text search and looks for verbatim matches, which is why the correct result is coming back. Full-text search is over tokens in inverted indexes. Everything else (filters, fuzzy, regex, prefix/wildcard, etc.) is over verbatim strings in a separate unprocessed/internal index.
Another way can be to set only the search analyzer on the field to keyword to avoid breaking the input query.
I am having an issue of single quotes around the array value.
I have an array which I have define as:
var latLongArray=[];
and the value I am getting is as below:
['{latitude:43.73747, longitude:7.163546}',
'{latitude:50.127339, longitude:8.60512}',
'{latitude:30.267, longitude:-97.743}' ]
I don't want single quotes, I tried using above all solution but not working for my issue.
I tried using below solutions to remove single quotes:
var newLatLongArray = latLongArray.join(',').replace(/'([^']+(?='))'/g, '$1');
// Remove single quotes
I am able to remove the single quotes but the newLatLongArray I am getting as a String but actually I want an array.
Any suggestion to get the value as an array with removing single quotes, please.
At your line var newLatLongArray = latLongArray.join(',').replace(/'([^']+(?='))'/g, '$1');, you tell to join your array, replace the single quotes but you never split again.
The join() function will transform your array to a string, the replace will replace the wanted characters and give a string so you just need to add a .split(',') at the end like this:
var newLatLongArray = latLongArray.join(',').replace(/'([^']+(?='))'/g, '$1').split(',');
Hope I helped you!
I'll go under the assumption you want an array of lat/long objects.
In that case, you could use:
var data = latLongArray.map(item => {
item = item.replace('latitude', '"latitude"').replace('longitude', '"longitude"');
return JSON.parse(item);
}));
I'm trying to filter a list of users from a Firebase query so that I only get users that are NOT listed in one of two arrays. The code I'm using doesn't work:
let users = snapshot.childSnapshots.map {
User(snapshot: $0)
}.filter{
guardiansArray.contains($0.key) == false || dependentsArray.contains($0.key) == false
}
If I remove the ==false code, I get the opposite effect of what I want: I get a list of users that ARE in either of the two arrays. How can I get the reverse effect?
Thanks!
It looks like you want to use && instead of ||.
I know lucene, just started to learn how to use solr. In the simple example, the way to add document is to used the example ../update -jar post.jar to add document, the question is without writing my own add document in java, using the same way (... post.jar), is there a way to add additional fields not in the document? For example, say my schema include name, age, id fields, but the document has no 'id' field but I want the id and its value to be included, of course I know what id and value I want but how do I include it?
Thanks in advanced!
I don't believe you can mix the two. You can use post.jar to add documents using arguments passed in on the commandline, a file, stdin or a simple crawl from a web page but there is no way to combine them. In the source code for post.jar you can see it's a series else if statements so they are mutually exclusive.
-Ddata args, stdin, files, web
Use args to pass arguments along the command line (such as a command
to delete a document). Use files to pass a filename or regex pattern
indicating paths and filenames. Use stdin to use standard input. Use
web for a very simple web crawler (arguments for this would be the URL
to crawl).
https://cwiki.apache.org/confluence/display/solr/Simple+Post+Tool
/**
* After initialization, call execute to start the post job.
* This method delegates to the correct mode method.
*/
public void execute() {
final long startTime = System.currentTimeMillis();
if (DATA_MODE_FILES.equals(mode) && args.length > 0) {
doFilesMode();
} else if(DATA_MODE_ARGS.equals(mode) && args.length > 0) {
doArgsMode();
} else if(DATA_MODE_WEB.equals(mode) && args.length > 0) {
doWebMode();
} else if(DATA_MODE_STDIN.equals(mode)) {
doStdinMode();
} else {
usageShort();
return;
}
if (commit) commit();
if (optimize) optimize();
final long endTime = System.currentTimeMillis();
displayTiming(endTime - startTime);
}
http://svn.apache.org/repos/asf/lucene/dev/trunk/solr/core/src/java/org/apache/solr/util/SimplePostTool.java
You could try to modify the code but I think a better bet would be to either pre-process your xml files to include the missing fields, or learn to use the API (either via Java or hitting it with Curl) to do this on your own.
We are trying to use Solr's spell check to do a "Did you mean?" type suggestion.
The problem we are having is that we are replacing the original term in the query with Solr's suggestions.
For example: a search for "10ks" (we are creating an events site) will return a suggestion of "5ks".
However, it seems the spell check is using "ks" rather than "10ks" as the term so when we replace "ks" with "5ks" we get 105ks. This then causes an infinite "did you mean" loop because Solr always uses "ks" rather than "10ks" in the spell check suggestions.
Here's the code that we use to replace suggestions in the original query.
/// <summary>
/// Method that takes the first suggestion for all the spelling and applys them to the keyword
/// </summary>
private string GetSuggestedQuery(string keyword, List<SpellCheck> suggestions)
{
if (suggestions != null)
{
for (var i = 0; i < suggestions.Count; i++)
{
keyword = keyword.Replace(suggestions.ElementAt(i).Query,
suggestions.ElementAt(i).Suggestions.First());
}
return keyword;
}
return null;
}
This works great for two word queries for example "runnig events" would get "running events".
The only thing I can think of is to do something naive like check for spaces in the original query and then replace the whole thing if the query contained spaces.
Look at the spellcheck.collate setting. It will return a re-written query in the way you are suggesting.
https://wiki.apache.org/solr/SpellCheckComponent#spellcheck.collate
Difficult to answer without looking at the field definition from your schema.xml. The Analyzers that will probably work for your case are:
WordDelimiterFilterFactory with split on letter-number transitions set to off (See: http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters#solr.WordDelimiterFilterFactory), along with the StandardTokenizerFactory.