![]() There might be a way to compute the number of matched fields and use that as a score by creating your own Lucene Query implementation, instead of using the default BooleanQuery (that's what the Hibernate Search query builder does). If you want better performance and are not afraid of difficulty. Obviously performance will not be great, since you will be running five queries instead of one. Then you can compute, for each result of the first query, how many of the other queries matched it. the fifth one will be a query on the "email" field only, and an additional filter on IDs to only consider the entities that matched the first query.the fourth one will be a query on the "phone" field only, and an additional filter on IDs to only consider the entities that matched the first query.the third one will be a query on the "lastName" field only, and an additional filter on IDs to only consider the entities that matched the first query.the second one will be a query on the "firstName" field only, and an additional filter on IDs to only consider the entities that matched the first query.the first one will be your query, as is.The easiest way is probably to run multiple queries: If what you want is to order the documents from the "most matching" to the "least matching", then Hibernate Search (Lucene, actually) already does that by default. I would recommend to rethink your requirements and see if your really need this "score". Score as 1 for objects which match any 1 field Score as 2 for objects which match any 2 fields ![]() Score as 3 for objects which match any 3 fields What i need is, score as 4 for objects which match all fields Log.debug("o query : " + om.writeValueAsString(o)) Log.debug("explanation query : " + explanation) ![]() String explanation = firstResult.toString() Here is my code luceneQuery = query = fullTextEntityManager.createFullTextQuery(luceneQuery, Notes.class)
0 Comments
Leave a Reply. |