Lucene.net query with value of field

Viewed 18

The codebase I'm working in is large and unwieldy. Codefiles, can be referenced by multiple projects, and projects can be referenced by multiple solutions. So even a seemingly innocuous change can break something in a completely different part of the system.

I wrote a Lucene index/search utility to make finding what needs to be updated much faster. Moreover it also outputs which project and solutions reference the file where the result was found so searches end up being safer too.

I have two indexes. One for code files, and one for project/solution files. Both indexes have Documents with two fields: Path, and Contents. First it searches the code index, against Contents and finds files that contain the search value. Then it uses the file name from the Path of that return as the search value against the Contents of project index.

For example: I'm looking for "snarf" and it's been found in blarch.cs:

|-C:\Path\To\The\blarch.cs
|  |-C:\Some\Path\To\The\First\project.csproj
|  |  |-C:\First\solution.sln
|  |  \-C:\Random\Location\For\Second\solution.sln
|  |-C:\A\Different\Path\To\The\Second\project.csproj
\  \  \-C:\Path\To\The\Third\Solution.sln

This works pretty well excepting when the file name where the search term is found is common. For example enumerations.cs or extensions.cs etc... in that case I get false positives.

How can I search the project index changing the Contents query so that it's looking for a value relative to the Path of the Document being searched?

System.IO.Path.GetRelativePath() can give me the value I need to find, but how do I change it on a per Document basis?

0 Answers
Related