0
votes

I am trying to write a lucene query to retrieve some pages in my website so I have the following:

string.Format("nodeName: ({0})^7 bodyText: ({0})^6", _searchTerm)

which means it will search for content that either has the nodeName or the bodyText that includes the _searchTerm variable

where I am struggling is that I also want it to not include any results that have a hideInNav flag set to 1 so I tried:

string.Format("nodeName: ({0})^7 bodyText: ({0})^6 +hideInNav: NOT(1)", _searchTerm)

However this is throwing up the following error:

Encountered " <NOT> "NOT "" at line 1, column 140.
Was expecting one of:
   "(" ...
   "*" ...
   <QUOTED> ...
   <TERM> ...
   <PREFIXTERM> ...
   <WILDTERM> ...
   "[" ...
   "{" ...
   <NUMBER> ...

As far as I can tell the query does have a ( after the NOT so I'm stumped as to where this is being expected

1

1 Answers

0
votes

Try this query:

string.Format("nodeName: ({0})^7 bodyText: ({0})^6 !hideInNav: (1)", _searchTerm)

The exclamation mark can also be changed to NOT:

string.Format("nodeName: ({0})^7 bodyText: ({0})^6 NOT hideInNav: (1)", _searchTerm)

See this page for an overview of the Lucene Query syntax (it's not the current version but I doubt it changed a lot)

Edit: maybe reversing you hideInNave statement will fix it:

string.Format("nodeName: ({0})^7 bodyText: ({0})^6 +hideInNav: (0)", _searchTerm) to check if it is zero or check if it is zero.

You might want to also download Luke to check the content of your index and see how values are saved.