How to combine two queries in Solr with ComplexPhraseQueryParser? - search

When I search in Solr 4.0 with the following two filter queries separately, it works as expected.
{!complexphrase inOrder=true}employeeName_t:"Mike R*"
empDate_dt:[2016-10-10T00:00:00Z TO 2016-10-10T23:59:59Z]
But I am not getting proper search results when I combine these two queries(Irrespective of the order).
{!complexphrase inOrder=true}employeeName_t:"Mike R*" AND empDate_dt:[2016-10-10T00:00:00Z TO 2016-10-10T23:59:59Z]
This query gives me zero search results in Solr
"response": {
"numFound":0,
"start":0,
"maxScore":0,
"docs":[]
}
empDate_dt:[2016-10-10T00:00:00Z TO 2016-10-10T23:59:59Z] AND {!complexphrase inOrder=true}employeeName_t:"Mike R*"
Whereas change in query order gives me parse exception as follows
"error":{
"msg": "org.apache.solr.search.SyntaxError: org.apache.lucene.queryparser.classic.ParseException: Cannot
parse 'employeeName_t:\"Mike': Lexical error at line 1, column 21. Encountered: after : \"\\"Mike\"",code:400
}
Using ComplexPhraseQueryParser for partial search in solr.Need to use both queries.Any suggestions to this would be greatly appreciated.

I suggest you to use fq parameter.
docs are retrieved with query as :"Mike R*" and filtered with dates specified in fq parameter.
Example:
q={!complexphrase inOrder=true}employeeName_t:"Mike R*"&fq=empDate_dt:["2016-10-10T00:00:00Z" TO "2016-10-10T23:59:59Z"]

Related

Irrelevant results returned from view search in arangodb

We have a collection AbstractEvent with field 'text', which contains 1~30 Chinese characters and we want to perform LIKE match with %keyword%, with high performance(less than 0.3 second, for more 2 million records).
After a bunch of effort, we decided to use VIEW and analyzer identity to do this:
FOR i IN AbstractEventView
SEARCH ANALYZER(i.text LIKE '%keyword%', 'identity')
LIMIT 10
RETURN i.text
And here is the definition of view AbstractEventView
{
"name":"AbstractEventView",
"type":"arangosearch",
"links":{
"AbstractEvent":{
"analyzers":[
"identity"
],
"fields":{
"text":{}
}
}
}
}
However, records returned contain irrelevant ones.
The flowlling is an example:
FOR i IN AbstractEventView
SEARCH ANALYZER(i.text LIKE '%速%', 'identity')
LIMIT 10
RETURN i.text
and the result is
[
"全球经济增速虽军官下滑",
"油食用消费出现明显下滑",
"本次国家经济快速下行",
"这场所迅速爆发的情况",
"经济减速风景空间资本大规模流出",
"苜蓿草众人食品物资价格不稳定",
"荤菜价格快速走低",
"情况快速升级",
"情况快速进展",
"四季功劳增速断崖式回落后"
]
油食用消费出现明显下滑and苜蓿草众人食品物资价格不稳定 are irrelavent.
We've been struggling on this for days, can anyone help me out? Thanks.
PS:
Why we do not use FULL-TEXT index?
full-text index indexed fields by tokenized text, so that we can not get matching '货币超发' when keyword is '货',because '货币' is recgonized as a word.
Why we do not use FILTER with LIKE operator directly?
Filtering without index will cost about 1 second and it is not acceptable.

How to search for a specific dynamic pattern of a field's in mongodb.?

I need to search mongodb collection for a specific pattern field. I tried using {$exists:true}; However, this gives results only if you provide exact field.
I tried using {$exists:true} for my field. But this does not give results if you give some pattern.
{
"field1":"value1",
"field2":"value2",
"field3":object
{/arjun1/pat1: 1,
/arjun2/pat2: 3,
/arjun3/pat3: 5
}
"field4":"value4",
}
From some field, I get the keys pat3 & field3. From this I would need to find out if the value /arjun3/pat3 exists in the document.
If I use {"field3./arjun3/pat3":{$exists:true}}, this would give me results. But the problem is I get only field3 and pat3 and I need to use some pattern matching like field3.*.pat3 and then use $expr or $exists; which I'm not exactly sure how to. Please help.
you could try something of this kind
db.arjun.find(
{"field3" : {
"$elemMatch" : { $and: [
{"arjun3.pat3" : {$exists:true}},
{"arjun3.pat3" : 5}
]
}}}
);
You can either go for regex (re module) for SQL like pattern matching, and compile your own custom wildcard. But if you don't want that then you can simple use the fnmatch module, it is a builtin library of python which allows wildcard matching for multiple characters (via*) or a single character (via ?).
import fnmatch
a = "hello"
print(fnmatch.fnmatch(a, "h*"))
OUTPUT:-
True

Azure search query to filter JSON values

I'm trying to frame Azure search query. The field type is collection(Edm.String) in Azure search index. This is how my JSON data to be filtered looks like : ["A","B"].
When I try to filter using the query Alphabet in 'A' it brings all the entries that has "A" in it. But when I try to frame the same query in my code like "'A' in Alphabet" it throws an exception stating:
"Invalid expression: Expression contains an unsupported OData language feature. Please revise your query and try again.
Parameter name: $filter".
Is there any other Azure query which I can use to filter my JSON data?
Note : I could not use eq as my field is multi valued and eq can handle only single values.
if you want to filter a collection that need to include multiple values, ie , you want to query all result whose collection all has "A" and "B" try the filter expression below :
Let's assume your collection field name is "alphabet"
$filter=alphabet/any(s: s eq 'A') and alphabet/any(s: s eq 'B')
The solution for this is to use search.ismatch query like search.ismatch('A,B','Alphabet','simple','any'). So the result will have search results of all the records having either A or B or both.
Reference : https://learn.microsoft.com/en-us/azure/search/query-odata-filter-orderby-syntax

Elastic Search: URI Search is inaccurate

I am searching via Webbrowser Firefox with the following URI:
http://localhost:9200/xyz-leads/lead/_search?q=datetimeHour:22_09_2015__12&&deliveryType:EMAIL
But I only get hits with deliveryType:RVS, not EMAIL.
If I search for deliveryType:RVS I get 3 hits.
I know there are 3 results for RVS and 0 for EMAIL with the datetimeHour above, in total.
I guess the standard behaviour of ElasticSearch is, that it ignores the second search value 'deliveryType' and uses only the first 'datetimeHour' if there are no results for both.
If I search for deliveryType:Email, then I want no hits in the response.
Do I need to set some additional ElasticSearch parameters?
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-uri-request.html
_source: {
country: "DEU",
brand: "A",
leadGroup: "TEST",
leadID: 108798,
deliveryType: "RVS",
datetime: 1442916913000,
datetimeFormatted: "22.09.2015 12:15:13",
datetimeHour: "22_09_2015__12",
datetimeDay: "22_09_2015"
}
The query string query you stuff into your URL (i.e. in the q=... parameter) needs to be well-formed according to the query string query syntax
Try this instead (i.e. using AND instead of &&)
http://localhost:9200/xyz-leads/lead/_search?q=datetimeHour:22_09_2015__12%20AND%20deliveryType:EMAIL

Elasticsearch get a selection of predefined types as result in one query

I've got an ElasticSearch index with a large set of product properties. They are all looking like that:
{'_id':1,'type':'manufacturer','name':'Toyota'},
{'_id':2,'type':'color','name':'Green'},
{'_id':3,'type':'category','name':'SUV Cars'},
{'_id':4,'type':'material','name':'Leather'},
{'_id':5,'type':'manufacturer','name':'BMW'},
{'_id':6,'type':'color','name':'Red'},
{'_id':7,'type':'category','name':'Cabrios'},
{'_id':8,'type':'material','name':'Steel'},
{'_id':9,'type':'category','name':'Cabrios Hardtop'},
{'_id':10,'type':'category','name':'Cabrios Softtop'},
... and 1 Mio. more ...
There are 4 different types of product properties existing: Categories, Manufacturers, Colors and Materials.
The question: How can i query with only one query (it's a settled performance requirement) the best matching result for each type?
So if i request a full text search query i.e. "Green Toyota Cabrios" i should get the following results:
{'_id':2,'type':'color','name':'Green'},
{'_id':1,'type':'manufacturer','name':'Toyota'},
{'_id':7,'type':'category','name':'Cabrios'},
{one matching result of the 'material'-type if found by the query}
That would be the perfect result set, always at maximum 4 results (for each 'type' one result). If there is no matching result for a specific type available there should be just 3 result items returned.
How is that possible with Elasticsearch? Thanks for your ideas!
I don't understand clearly your use case. What are you indexing in fact?
If you index cars, you should index it like:
{
"color": "Green",
"manufacturer": "Toyota",
"category": "Cabrios"
}
That said, from the question you ask:
You can probably define your fields as not_indexed. That way, if you search for "Green Toyota Cabrios" if field "name" you won't get "Cabrios Hardtop".
Not sure I really answered but I don't see your use case...

Resources