-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added anykeyword and anyfield pseudo search fields #1876
Conversation
// special case for searching a single keyword | ||
if (fieldPattern.matcher("keyword").matches()) { | ||
if (entry.hasField(FieldName.KEYWORDS)) { | ||
List<String> keywords = new ArrayList<>(entry.getKeywords()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not a simple stream on the list with anyMatch (returns a boolean)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And you could even use that together with the prev line if you use your getFieldOptional method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The getFieldOptional is no more. ;-)
You mean:
return entry.getKeywords().stream().anyMatch(this::matchFieldValue);
?
Could work. In the most recent version I swapped order of hasField and matcher as I expected the first one to be faster. Still, I think getKeywords() returns an empty list if the field is not set, so doesn't really need it.
I'm thinking that the distinction between keyword and keywords is not enough. What do you suggest? anykeyword? singlekeyword? |
Also, when writing a bit more search queries for the tests: is
|
Difficult question... To me |
Be aware of backwards compatibility. People may be used to "allFields" already.. |
|
|
||
for (String field : matchedFieldKeys) { | ||
for (String field : fieldsKeys) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could here do the same as above, just with return fieldsKeys.stream().filter(this::matchFieldValue).isPresent()
The nice thing is that all operations like map., filter etc are only performed if the value inside the optional is present, so absolutely type safe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite. This has to be wrapped in an if
which executes return true;
Overall lgtm, you could replace that one case with a stream too and maybe add some test regarding umlauts...(not sure if they are actually handled correctly) |
I find the
|
@JabRef/developers Opinions? Personally, I think that adding a search operator which only can be used for a specific field is a bit counter-intuitive. |
I like For an operator I would expect it to work everywhere, not containing any special semantics for a specific field. |
But one could also have different fields with values separated by some character ("keyword fields"). For example, it would make sense to search for entries in specific groups or some user defined fields. But one probably doesn't want to define |
You do have a point, but:
Hence, this has to be postponed and done by someone else. If it is likely Clearly, it would also be much better if (Btw, I think that one can already search for groups, although it will be |
Alternative: Use Apache Lucene's Syntax - see #1975 |
We discussed the following at the devcall: The search parser should be extended to support an The long term goal would be to move towards a sophisticated query parser, such as Lucene. However, the effort for this and the required time is quite unsure. |
I do not get it. First, So, no, as I do not understand how it should be done (in a way that makes sense). |
Dumb question: What currently happens when searching for a keyword? Isn't
substring matching enough?
|
Say you have two keywords |
OK for me. |
@oscargus based on your description, the problem is not specific to the keywords fields. For example, I can't find the author I think the standard solution is: only match whole words (i.e. |
👍 for the wildcard query option. e.g. * and ? |
As I wrote there are a few more fields, yes, put providing a generic split My suggestion is that we add |
👍 - @oscargus please solve https://github.com/JabRef/jabref/pull/1876/files#r78694966, then we can merge and then we can work on other fields in another PR. I'm trying to keep the PRs small and want to merge them fast. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I can live with anykeyword
but find it still a suboptimal/incomplete solution.
The anyfield
is construction is something I don't understand. I thought JabRef searches all fields by default. Does fruity and keywords=apple
work? If not then this is probably a bug and should be fixed. Could you please explain the purpose of anyfield
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I can live with anykeyword
but find it still a suboptimal/incomplete solution.
The anyfield
is construction is something I don't understand. I thought JabRef searches all fields by default. Does fruity and keywords=apple
work? If not then this is probably a bug and should be fixed. Could you please explain the purpose of anyfield
.
The new github review is a bit strange... no idea why there are now two comments and one approval. It should be actually "one comment" 😄 |
Correct, Incomplete, yes. But not really possible to generalize. Hence the need for more PRs improving the search, which, I guess, can always be improved. |
# Conflicts: # CHANGELOG.md # src/test/java/net/sf/jabref/logic/search/SearchQueryTest.java
See #1633 (comment)
Will add tests etc if it is a good idea and works.