Lucene query syntax - lucene

I want to write a Lucene query which is the equivalent of the following SQL
where age = 25
and name in ("tom", "dick", "harry")
The best I've come up with so far is:
(age:25 name:tom) OR
(age:25 name:dick) OR
(age:25 name:harry)
Is there a more succinct way to write this?
Thanks,
Don

age:25 AND name:(tom OR dick OR harry)
alternatively
+age:25 +name:(tom OR dick OR harry)

Does this work?
age:25 AND (name:tom OR name:dick OR name:harry)
I understand this may not be what you're looking for. I didn't know if the purpose of your question was to factor out the age:25 clause or if it was to eliminate the name: prefixes.
If you make name your QueryParser's default field, you could reduce this down to:
age:25 AND (tom OR dick OR harry)

It's not much more succinct, but you can try:
(age:25) AND (name:tom OR name:dick OR name:harry)

Related

String masking with Regex at Oracle

I want to mask name and surname in Oracle.
For example; John Smith => Jo** Sm**
I can write a PL/SQL function. But i want to do this with regex. I can't write the right template. Is regex the right solution? Is there anyone who can help?
If you want todo it with regexp you can use the following:
REGEXP_REPLACE('John Smith', '(\w{2})\w+', '\1**')

Regex in redshift

I have a problem.. I need to extract from this field:
exchange<=><br>type<=>full<br>cont<=>part<br>req<=>no<br>money<=>money<br>money<=>3100,4000,0,month<br>boss<=>0
five informations:
full
part
3100
4.4000
5.month
I have tried to use regexp_substr():
regexp_substr(column,'type<=>[^<br>]*') but I dont have any knowledge about regex and I cant do it in a properly way.. can you help me with that?
I never worked with redshift but with regex I can help you:
"(type|cont|money)<=>([^<,]+)(,([^<,]+),[^<,]+,([^<,]+))?"
The capture number 4 in the string you put as an example it will capture all you need, it even exclude the 0 :
Group 1: money
Group 2: 3100
Group 3: ,4000,0,month
Group 4: 4000
Group 5: month
In case you have problems, tell me.
If you want to master your regex skills I can teach you, it will be useful.

Hibernate Search with Lucene Query for first and last name together

I have attempted this with phrase, wildcard and keyword queries but nothing really works perfectly.
...
#Field(name = "firstLastName", index = org.hibernate.search.annotations.Index.YES, analyze = Analyze.NO, store = Store.NO)
public String getFirstLastName() {
return this.firstLastName;
}
...
Now I want to query this field and return the correct results if a user types John Smith, Smith John or Smith Jo* or John Smi*....
junction = junction.should(qb.keyword().wildcard().onField("firstLastName")
.matching("John Smith*").createQuery());
If I search for just Smith or John given a keyword query, I get a hit. I am not analyzing the field as I didn't think I needed to but I tried it both ways with no success...
Several issues here:
You need to use an analyzer, be it only to split the strings on whitespaces. Define an analyzer and assign it to your field.
You can't use wildcard queries if you want the strings to be analyzed: wildcard queries are not analyzed. You should use an EdgeNGramFilter instead.
This answer to a very similar question will probably help: Hibernate Search: How to use wildcards correctly?

URL encoding a SPARQL query for dbpedia.org

I am trying to write a code (in ABAP) for URL encoding a SPARQL query for dbpedia.org.
Is there any reference code or method?
Ex: Input:
select distinct ?Concept where {[] a ?Concept} LIMIT 100
Output:
http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=select+distinct+%3FConcept+where+%7B%5B%5D+a+%3FConcept%7D+LIMIT+100&format=text%2Fhtml&timeout=0&debug=on
Thanks
Krishna
Disclaimer: I know nothing about ABAP.
Having said that, I'd be surprised if there isn't a library function to do that. If not, you can try porting the one from the JDK:
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/java/net/URLEncoder.java#URLEncoder

How does FAST ESP's xrank operator work?

I have a bunch of documents in my index.
They all have "text" in field1. One has "boosttext" in field2.
I want FAST to put the document with "boosttext" to the front of the result set.
I tried this FQL query:
and(field1:string("text"), xrank(field2:string("boosttext", mode="AND"))
However, this will filter out all documents that do not have "boosttext" in field2 !!!
Has anyone successfully used xrank and can give me a hint? Thanks in advance.
-- Bob
... it seems that the following FQL expression works:
rank(field1:string("text"), xrank(field2:string("boosttext"))
-- Bob
xrank(field1:string("text"), field2:string("boosttext"), boost=100)
See: http://msdn.microsoft.com/en-us/library/ff394462.aspx
xrank(or(cat, dog), thoroughbred, boost=500, boostall=yes)