Is it possible to search for a phrase in opengrok containing curly brackets?
Asked Answered
B

3

5

I have tried using something like "struct a {" and "struct a {" to look for the declaration of "a". But it seems opengrok just ignores the curly brackets. Is there a way to search for the phrase "struct a {"?

Brain answered 13/1, 2014 at 23:52 Comment(0)
S
3

Grok supports escaping special characters that are part of the query syntax. The current list of special characters are

+ - && || ! ( ) { } [ ] ^ " ~ * ? : \

To escape these character use the \ before the character. 
For example to search for (1+1):2 use the query: \(1\+1\)\:2
Scorecard answered 27/10, 2014 at 22:20 Comment(2)
The backspace does not appear to work as an escape character. I'm trying to search our codebase for any instances of SELECT *, so i search using: "SELECT *". This query returns the same number of results as the "SELECT" query. The backslash was ignored...Urinary
How about ">" as in -> ?Sclerotomy
E
1

You should be able to search with "struct a {" (with quotes)

Ernesternesta answered 26/3, 2014 at 6:13 Comment(0)
K
0

From OpenGrok documentation:

Escaping special characters:

Opengrok supports escaping special characters that are part of the query syntax. Current special characters are:

+ - && || ! ( ) { } [ ] ^ " ~ * ? : \ /

To escape these character use the \ before the character. For example to search for (1+1):2 use the query: (1+1):2

NOTE on analyzers: Indexed words are made up of Alpha-Numeric and Underscore characters. One letter words are usually not indexed as symbols! Most other characters (including single and double quotes) are treated as "spaces/whitespace" (so even if you escape them, they will not be found, since most analyzers ignore them).

The exceptions are: @ $ % ^ & = ? . : which are mostly indexed as separate words. Because some of them are part of the query syntax, they must be escaped with a reverse slash as noted above.

So searching for +1 or + 1 will both find +1 and + 1.

Valid FIELDs are

full

Search through all text tokens (words,strings,identifiers,numbers) in index.

defs

Only finds symbol definitions (where e.g. a variable (function, ...) is defined).

refs

Only finds symbols (e.g. methods, classes, functions, variables).

path

path of the source file (no need to use dividers, or if, then use "/"

  • Windows users, "" is an escape key in Lucene query syntax! Please don't use "", or replace it with "/"). Also note that if you want just exact path, enclose it in "", e.g. "src/mypath", otherwise dividers will be removed and you get more hits.

hist

History log comments.

type

Type of analyzer used to scope down to certain file types (e.g. just C sources). Current mappings: [ada=Ada, asm=Asm, bzip2=Bzip(2), c=C, clojure=Clojure, csharp=C#, cxx=C++, eiffel=Eiffel, elf=ELF, erlang=Erlang, file=Image file, fortran=Fortran, golang=Golang, gzip=GZIP, haskell=Haskell, jar=Jar, java=Java, javaclass=Java class, javascript=JavaScript, json=Json, kotlin=Kotlin, lisp=Lisp, lua=Lua, mandoc=Mandoc, pascal=Pascal, perl=Perl, php=PHP, plain=Plain Text, plsql=PL/SQL, powershell=PowerShell script, python=Python, ruby=Ruby, rust=Rust, scala=Scala, sh=Shell script, sql=SQL, swift=Swift, tar=Tar, tcl=Tcl, troff=Troff, typescript=TypeScript, uuencode=UUEncoded, vb=Visual Basic, verilog=Verilog, xml=XML, zip=Zip] The term (phrases) can be boosted (making it more relevant) using a caret ^ , e.g. help^4 opengrok - will make term help boosted

Opengrok search is powered by Lucene, for more detail on query syntax refer to Lucene docs.

Kt answered 21/2, 2022 at 10:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.