I have a sample Solr schema as follows
isPublic = boolean
source = facebook| twitter | wordpress
I want to write a query which returns all documents from the index which matches either the isPublic = true or isPublic is false and source= facebook. Something like this
solrUrl/?q=blah&fq=(isPublic:true OR (isPublic:false AND source:facebook))
Is such a thing possible or should I search the index two times with each of these conditions and then combine + de-duplicate the results?
Sure you can run such a filter query, but I think that particular query will not get you the results you're looking for, see this question about it. A logically equivalent query would be: isPublic:true OR source:facebook
Related
I checked this question What is the difference between must and filter in Query DSL in elasticsearch? and read answers.
As far as I understood must and filter should return same result. Am I right? But when I change filter query to must, I receive more result? What I am doing wrong?
I compared filter and must query and got different result.
Must query gives you some score that is used to add to the total score of the doc.
Filter query does not add any score. It is just used to decide whether a doc is returned or not in the result set.
By just looking at the screenshot of the query attached, when you change filter query to must query it starts adding some value to the total score of the doc.
Since you are using min_score condition, the must clause makes more docs exceed 0.2 score and hence more docs are returned in the final result set.
Rest things will be more clear when you share the complete query.
Im tring to understand the DSL query i needed if i want to make a search from a result set i got. means i have an initial term search, then i want make another query upon the previous result.
lets say i a have 10 documents with a sharing identifier between them, each document has a description field. i want to search first all the documents containing the value 'Hello' in the description and then take their id's, and search the document containing the value 'good by'.
thanks.
No need to execute two queries, you can use filter context that will filter out the results.filter parameter will filter out documents that do not match, and will also not affect the score for matching documents.
Filter context is in effect whenever a query clause is passed to a
filter parameter, such as the filter or must_not parameters in the
bool query, the filter parameter in the constant_score query, or the
filter aggregation.
Refer this to know more about Query and Filter contexts
What is the meaning of this query in lucene ?
Query query =new QueryParser(Version.LATEST,"*",analyzer).parse("value");
It creates a QueryParser for the field "*" (I'm not sure if actual wildcards are allowed here - try!), using the specified analyzer. It then parses the textual query ("value") for that field. This returns a Query, which you can then use for searching through searcher.Search(query);.
I have two users with name 'Alex' and 'Andrei'. When i write query like 'A', I get 0 results. I have to search with the full name and matching capitalization to get a result.
I want for example just query for 'e' end receive 2 records.
Session s = session.getCurrentSession();
FullTextSession fullTextSession = Search.getFullTextSession(s);
QueryBuilder qb = fullTextSession.getSearchFactory()
.buildQueryBuilder().forEntity(User.class).get();
org.apache.lucene.search.Query q = qb
.keyword().onFields("name")
.matching(query)
.createQuery();
org.hibernate.Query hibQuery =
fullTextSession.createFullTextQuery(q, User.class);
List<User> results = hibQuery.list();
You are not showing how you index the first names. This is as well important. For example if you store index them un-analyzed, you need to take indeed capitalization into account. Also as mentioned in the comment, you need to look at the right analyzer. You case would only work if you were to use wildcard queries.
On a tangent, I don't know how close your example is to your actual usecase, but searching for a single character is probably not a typical free-text search use-case.
This particular behavior reminds me one error I got once.
'A' is a stop word (in English language) used by the standard analyzer of Hibernate Search, so you have to precise a custom analyser without this stop word.
These Links could help you
To use a custom analyzer: https://docs.jboss.org/hibernate/search/3.1/reference/en/html/search-mapping.html
To understand what I mean with 'a' like a stop word: Getting error on a specific query
We're running Solr 3.6 and are trying to apply a conditional sort on the result set. To clarify, the data is a set of bids, and we want to add the option to sort by the current user's bid, so it can't function as a regular sort (as the bid will be different for each user that runs the query).
The documents in the result set include a "CurrentUserId" and "CurrentBid" field, so I think we need something like the following to sort:
sort=((CurrentUserId = 12345) ? CurrentBid : 0) desc
This is just pseudocode, but the idea is that if the currentUserId in Solr matches the user Id (12345 in this example), then sort by CurrentBid, otherwise, just use 0.
It seems like doing a sort by query might be the way to go with achieving this (or at least form part of the solution), using something like the following query:
http://localhost:8080/solr/select/?q=:&sort=query(CurrentUserId:10330 AND CurrentBid:[1 TO *])+desc
This doesn't seem to be working for me though, and results in the following error:
sort param could not be parsed as a query, and is not a field that exists in the index: ...
The Solr documentation indicates that the query function can be used as a sort parameter from Solr 1.4 onwards, so this seems like it should work.
Any advice on how to go about achieving this would be greatly appreciated.
According to the Solr Documentation link you provided,
Any type of subquery is supported through either parameter dereferencing $otherparam or direct specification of the query string in the LocalParams via "v".
So based on the examples and your query, I think one or both of the following should work:
http://localhost:8080/solr/select/?q=:&sort=query($qq)+desc&qq=(CurrentUserId:10330 AND CurrentBid:[1 TO *])
http://localhost:8080/solr/select/?q=:&sort=query({v='CurrentUserId:10330 AND CurrentBid:[1 TO *]'})+desc