Lucene Query Syntax of field with a space - lucene

I am trying to perform two Lucene queries. The first one works. The second does not. My first query looks like this:
level:"dangerous"
My second query looks like this:
IP address:"11.22.333.444"
I'm not getting a query error. However, I know there are documents with the matching IP address. For that reason, I suspect the space between "IP" and "address" is causing the problem. However, I'm not an expert in Lucene. So, I'm not sure if I'm correct in that.
When I look at my result set using PostMan, I can see a document with a field that looks like this:
"IP address": "11.22.333.444"
Can someone please tell me if my query is correct? Or, if I'm missing something?
Thank you!

Yes, that space is the problem.
The space in a field name is allowable, but conflicts with query parser syntax. You are essentially running two subqueries combined as SHOULD clauses (ie, an OR):
IP
address:"11.22.333.444"
You can escape the space using a single slash before the space, like:
IP\ address:"11.22.333.444"

Related

LIKE or REGEX trouble

I'm tyring to pull everything out of a column when the word assistant is present with something like below:
SELECT *
FROM table
WHERE field LIKE '%assistant%'
but this is not working. I am not getting an error and it is filtering the data somehow but it appears to actually be filtering my requested values OUT (I have verified the values exist). Can anyone explain what is wrong with attempt or how I can do this in regex with REGEXP_LIKE?
For regex, the pattern would be anythingASSISTANTanything
Does this do what you want?
WHERE LOWER(field) LIKE '%assistant%'

Need a way of finding special characters in data using SQL query

I am trying to find special characters in any of my fields that are not in the range of a-zA-Z0-9. However if I try this query:
select Name from table where Name like '%[?]%'
I get two records:
???? ?????
Fixed?????
Which is what I want. However, since I don't know what the special chars will be I need to use an exclusion of data that has mixed characters:
select Name from table where Name NOT like '%[a-zA-Z0-9]%'
Since this excludes all records with a-zA-Z0-9 I only get:
???? ?????
But I also need to get the 'Fixed?????' result. I need to get the data that has the special character merged into it.
I am bit at a loss as how to do this. I've seen this done with shell scripts or 'vi' (LIST), but in SQL that's not so easy.
Has anyone out there solved this?
Try this code:
select Name from table where Name like '%[^0-9a-zA-Z ]%'
Thank you for replying. I had tried your suggestions but I was still getting more results. However, it looks like you can get very specific with the exclusion. Eventually I ended up adding results from the data I got.
Like this:
select Name from table where Name LIKE '%[^0-9a-zA-Z() -._/\:=,]%'
This finally gave me what I was looking for. Although new issue I have now is how to suppress the [] brackets which apparently also are found in the data:
???? ?????
HP PCI 10/100Base-TX Core [100BASE-TX,FD,AUTO,TT=1500]
Fixed?????
Adding those brackets into the query breaks the array boundary:
'%[^0-9a-zA-Z() -._/\:=,**[]**]%'
However, this is something I can handle. As long as I am not getting "all" the data.
LIKE '%[^0-9a-zA-Z]%'
numbers (0-9), lowercase alphas (a-z), uppercase alphas (A-Z). The "^" makes that a "NOT" one of these things

DB2 complex like

I have to write a select statement following the following pattern:
[A-Z][0-9][0-9][0-9][0-9][A-Z][0-9][0-9][0-9][0-9][0-9]
The only thing I'm sure of is that the first A-Z WILL be there. All the rest is optional and the optional part is the problem. I don't really know how I could do that.
Some example data:
B/0765/E 3
B/0765/E3
B/0764/A /02
B/0749/K
B/0768/
B/0784//02
B/0807/
My guess is that I best remove al the white spaces and the / in the data and then execute the select statement. But I'm having some problems writing the like pattern actually.. Anyone that could help me out?
The underlying reason for this is that I'm migrating a database. In the old database the values are just in 1 field but in the new one they are splitted into several fields but I first have to write a "control script" to know what records in the old database are not correct.
Even the following isn't working:
where someColumn LIKE '[a-zA-Z]%';
You can use Regular Expression via xQuery to define this pattern. There are many question in StackOverFlow that talk about patterns in DB2, and they have been solved with Regular Expressions.
DB2: find field value where first character is a lower case letter
Emulate REGEXP like behaviour in SQL

Issue using wildcards in index with multiple start points

With multiple start points, if i provide the full name (value) of the key 'Name' the cypher query works.
This Works:
start n=node:na('NAME:("JERI, MICHAEL M", "ANDREW, TONNA", "JILLSO, DAVID")')
return n.NAME
Say, if i wish to use wildcards on Name key, something like this:
start n=node:na('NAME:("JERI*", "ANDREW*", "JILLSO*")')
return n.NAME
This doesn't work. It gives me zero rows.
It would be great if someone could help me with the correct way to achieve this.
I think this may be due to the double quotes, making Lucene query parser 3.6.2 (used in Neo4j 1.9) parse the terms as phrases instead of single terms. And wildcards are only supported for single terms, not phrases.

Performing an ASP.NET database search with StartsWith keyword

I have a query. I am developing a site that has a search engine. The search engine is the main function. It is a business directory site.
A present I have basic search sql that searches the database using the "LIKE" keyword.
My client has asked me to change the search function so instead of using the "Like" keyword they are after something along the lines of the "Startswith" keyword.
To clarify this need here is an example.
If somebody types "plu" for plumbers in the textbox it currently returns, e.g.,
CENTRE STATE PLUMBING & ROOFING
PLUMBING UNLIMITED
The client only wants to return the "PLUMBING UNLIMITED" because it startswith "plu", and doesn't "contain" "plu"
I know this is a weird and maybe silly request, however does anyone have any example SQL code to point me in the right direction on how to achieve this goal.
Any help would be greatly appreciated, thanks...
how about this:
SELECT * FROM MyTable WHERE MyColumn LIKE 'PLU%'
please note that the % sign is only on the right side of the string
example in MS SQL
Instead of:
select * from professions where name like '%plu%'
, use a where clause without the leading %:
select * from professions where name like 'plu%'
LIKE won't give you the performance you need for a really effective search. Looking into something like Lucence or your engine's Full Text Search equivalent.