title: Lucene in Neo4j has some misbehaviours in terms of reliable search querys - compared to OrientDB
body: <p>I'm still in the evaluation of <strong>Neo4j</strong> vs. <strong>OrientDB</strong>. Most importantly I need Lucene as full-text index engine. So I created on both databases the same schema with the same data (300Mio lines). I'm also experienced with querying different things in both systems. I used the Standard Analyzer on both sides. The OrientDB test query results are all fine and really good in terms of reliability and speed. The speed of Neo4j is also ok but the results are kind of bad in most of the cases. So let's come to the different issues I have with Neo4j Lucene indexing. I always give you an example of how it would look in OrientDB and which result set you should be getting out of the query.</p>
  
  <p>So in these examples, there are Applns that have title(s). Titles are indexed with Lucene in both databases. Applns also have an ID just to demonstrate the ordering. At the end of each query I have some <strong>questions</strong> about them. It would be great to get some <strong>feedback</strong> or even <strong>answers</strong> about them.</p>
  
  <h2>Query #0: One word query with no order</h2>
  
  <p>Well this query is very simple. It shall be tested how the database behave if there is just a simple word and nothing else. As you can see the Neo4j result is way longer then the one from OrientDB. OrientDB is using TFIDF to keep the results short and more reliable to the actual search. As you can see as first result in OrientDB, there is title with SOLAR. That is totally missing in Neo4j, too.</p>
  
  <p>In Neo4j: <strong>START n=node:titles('title:solar') RETURN n.title,n.ID LIMIT 10</strong></p>
  
  <ol>
  <li><p>SOLAR RADIATION SHIELDING PARTICULATE AND SOLAR RADIATION SHIELDING RESIN MATERIAL DISPERSED WITH ...    38321319</p></li>
  <li><p>Solar module for cooling solar cells on the underside of a solar panel has air inlet and outlet openings ... 12944121</p></li>
  <li><p>Solar construction component for solar thermal assemblies, solar thermal assembly, method for operating a solar...   324146113</p></li>
  <li><p>...</p></li>
  </ol>
  
  <p>In OrientDB: <strong>SELECT title,ID FROM Appln WHERE title LUCENE "solar" LIMIT 10</strong></p>
  
  <ol>
  <li><p>SOLAR    24900187</p></li>
  <li><p>Solar unit and solar apparatus   1876343</p></li>
  <li><p>Solar module with solar concentrator 13496706</p></li>
  <li><p>...</p></li>
  </ol>
  
  <p>Questions:</p>
  
  <ol>
  <li>Why is Neo4j not using TFIDF or what do they use instead?</li>
  <li>Is Neo4j able to use some ordering of the keyword match?</li>
  <li>Is it possible to change TFIDF to somethign else in OrientDB?</li>
  </ol>
  
  <h2>Query #1: One word query with order by ID</h2>
  
  <p>Neo4j is ordering the ID's before using TFIDF. As known from Query#0 Neo4j is not using TFIDF so it's basically just searching via first results of the Lucene query. In OrientDB besides it's still searching by good TFIDF's and then ordering.</p>
  
  <p>In Neo4j: <strong>START n=node:titles('title:solar') RETURN n.title,n.ID ORDER BY n.ID ASC LIMIT 10</strong></p>
  
  <ol>
  <li><p>Stackable flat-roof/floor frame for solar panels 318</p></li>
  <li><p>Method for producing contact for solar cells 636</p></li>
  <li><p>Solar cell and fabrication method thereof    1217</p></li>
  <li><p>...</p></li>
  </ol>
  
  <p>In OrientDB: <strong>SELECT title,ID FROM Appln WHERE title LUCENE "solar" ORDER BY ID ASC LIMIT 10</strong></p>
  
  <ol>
  <li><p>Solar unit and solar apparatus    1876343</p></li>
  <li><p>Solar module with solar concentrator 13496706</p></li>
  <li><p>SOLAR TRACKER FOR SOLAR COLLECTOR    16543688</p></li>
  <li><p>...</p></li>
  </ol>
  
  <p>Questions:</p>
  
  <ol>
  <li>How would a search in OrientDB look like that should be ordered by the ID and still matching the best TFIDF of them.</li>
  <li>Is there a way in Neo4j to order the Lucene match before ordering by the ID?</li>
  </ol>
  
  <h2>Query #2: One word with using a star search</h2>
  
  <p>Star search had no influence on the Neo4j results. OrientDB results changed in a good way.</p>
  
  <p>In Neo4j: <strong>START n=node:titles('title:solar*') RETURN n.title,n.ID ORDER BY n.ID ASC LIMIT 10</strong></p>
  
  <ol>
  <li><p>Stackable flat-roof/floor frame for solar panels 318</p></li>
  <li><p>Method for producing contact for solar cells 636</p></li>
  <li><p>Solar cell and fabrication method thereof    1217</p></li>
  <li><p>...</p></li>
  </ol>
  
  <p>In OrientDB: <strong>SELECT title,ID FROM Appln WHERE title LUCENE "solar*" ORDER BY ID ASC LIMIT 10</strong></p>
  
  <ol>
  <li><p>High performance solar methane generator 8354701</p></li>
  <li><p>All-plastic honeycomb solar water-heater 8355379</p></li>
  <li><p>Plate type solar energy heat collector plate core and its manufacturing method   8356173</p></li>
  <li><p>...</p></li>
  </ol>
  
  <p>Questions:</p>
  
  <ol>
  <li>Does Neo4j ignore star searches?</li>
  </ol>
  
  <h2>Query #3: Searching for 2 words devided by a space</h2>
  
  <p>The strange here is that you need to change 'title:solar panel' to that query here. Otherwhise you just get errors. OrientDB seems good so far.</p>
  
  <p>In Neo4j: <strong>START n=node:titles(title="solar panel") RETURN n.title,n.ID ORDER BY n.ID ASC LIMIT 10</strong></p>
  
  <ol>
  <li>Returned 0 rows in 817 ms</li>
  </ol>
  
  <p>In OrientDB: <strong>SELECT title,ID FROM Appln WHERE title LUCENE "solar panel" ORDER BY ID ASC LIMIT 10</strong></p>
  
  <ol>
  <li><p>SOLAR PANEL  1584567</p></li>
  <li><p>SOLAR PANEL  1616547</p></li>
  <li><p>SOLAR PANEL  2078382</p></li>
  <li><p>SOLAR PANEL  2078383</p></li>
  <li><p>Solar panel  2178466</p></li>
  <li><p>...</p></li>
  </ol>
  
  <p>Questions:</p>
  
  <ol>
  <li>Why does Neo4j need a special Query here to at least don't throw any error?</li>
  <li>Why is the query failing and not giving anything back? I know that Neo4j is searching here for lower letters, so it's case sensitive. But why it is like this? I mean I use the default analyzer and the doc of Neo4j Lucene says it's true, so it means to_lower_letter.</li>
  </ol>
  
  <h2>Query #4: Now searching for the same query in capital letters</h2>
  
  <p>The same issue like in #3. In Neo4j just searching returning the capital letters results of the words. OrientDB results looking fine again.</p>
  
  <p>In Neo4j: <strong>START n=node:titles(title="SOLAR PANEL") RETURN n.title,n.ID ORDER BY n.ID ASC LIMIT 10</strong></p>
  
  <ol>
  <li><p>SOLAR PANEL  348800</p></li>
  <li><p>SOLAR PANEL  420683</p></li>
  <li><p>SOLAR PANEL  1393804</p></li>
  <li><p>SOLAR PANEL  1584567</p></li>
  <li><p>SOLAR PANEL  1616547</p></li>
  <li><p>...</p></li>
  </ol>
  
  <p>In OrientDB: <strong>SELECT title,ID FROM Appln WHERE title LUCENE "SOLAR PANEL" ORDER BY ID ASC LIMIT 10</strong></p>
  
  <ol>
  <li><p>SOLAR PANEL  1584567</p></li>
  <li><p>SOLAR PANEL  1616547</p></li>
  <li><p>SOLAR PANEL  2078382</p></li>
  <li><p>SOLAR PANEL  2078383</p></li>
  <li><p>Solar panel  2178466</p></li>
  <li><p>...</p></li>
  </ol>
  
  <p>Questions:</p>
  
  <ol>
  <li>Same question like in #3, how to search with to_lower_letter?</li>
  </ol>
  
  <h2>Query #5: Combining two words and using the star search</h2>
  
  <p>Here I want to combine words search with star search. But with the equal search I'm not able to find matches because he expects the star as usual sign in the title. But I'm not able to say 'title:SOLAR PANEL*'. That's also forbidden. In OrientDB everything is fine.</p>
  
  <p>In Neo4j: <strong>START n=node:titles(title="SOLAR PANEL*") RETURN n.title,n.ID ORDER BY n.ID ASC LIMIT 10</strong></p>
  
  <ol>
  <li>Returned 0 rows in 895 ms</li>
  </ol>
  
  <p>In OrientDB: <strong>SELECT title,ID FROM Appln WHERE title LUCENE "SOLAR PANEL*" ORDER BY ID ASC LIMIT 10</strong></p>
  
  <ol>
  <li><p>SOLAR PANELS     1405717</p></li>
  <li><p>SOLAR PANEL   1584567</p></li>
  <li><p>SOLAR PANEL   1616547</p></li>
  <li><p>SOLAR PANEL   2705081</p></li>
  <li><p>Solar Panel   2766555</p></li>
  <li><p>...</p></li>
  </ol>
  
  <p>Questions:</p>
  
  <ol>
  <li>How can you combine some words with the star search in Neo4j?</li>
  </ol>
  
  <h2>Query #6: Counting query results</h2>
  
  <p>The last thing I really need is a fast lookup how many results are there overall. Here Neo4j is finding a result way faster but always finding less matches then OrientDB. Searching for Solar is kind of close to each other. But another test was not that close.</p>
  
  <p>In Neo4j: <strong>START n=node:titles("title:Solar") RETURN count(*)</strong></p>
  
  <p>143211 in 220 sec</p>
  
  <p>In OrientDB: <strong>SELECT count(*) title FROM Appln WHERE title LUCENE "Solar" LIMIT -1</strong></p>
  
  <p>148029 in 50 sec</p>
  
  <p>Questions:</p>
  
  <ol>
  <li>How can that lookup times be improved on both systems?</li>
  <li>Why does both systems find different number of matches? Also happens on other keywords. Maybe other indexing eninge used?</li>
  </ol>
  
  <p>Well that is everything for now. If you need any other query just tell me and I deliver it.
  I think it's very important to compare the Lucene implementation because with Millions of nodes Lucene has to many advantages. Thanks for any small tip.</p>
  
  <p>Btw: please don't give tips about using Java code instead for the query. I want to use Cypher because the request shall be done in the browser, like in OrientDB. I know that everything here is easily be done with Java code. Thank you.</p>