Question: I have an Orient DB class "user" with "FirstName" and "LastName" fields which may contain one or more words (users can have more first and last names). There is a FULLTEXT LUCENE index on these fields ["FirstName","LastName"]. I can create a query to search for any word in these fields: 

```
SELECT FROM user WHERE ([FirstName,LastName] LUCENE "Peter")

```

I can also create query to search for multiple keywords like:

```
SELECT FROM user WHERE ([FirstName,LastName] LUCENE "Peter AND Fa*")

```

But I can't figure out how to search for multiple matches of the same word. I tried:

```
SELECT FROM user WHERE ([FirstName,LastName] LUCENE "Peter AND Peter")

```

but it will return the same set as the first query.

I tried to find the answer in the Orient DB manual, e.g. here: <http://orientdb.com/docs/2.0/orientdb.wiki/FullTextIndex.html> but didn't find any guidance that led me to the solution.

Does anybody know how to deal with such cases?

*EDITED* - It seems, that I didn't specify the question accurately. So I add a short example here:

Suppose that my DB has 3 classes:

```
Nr  FirstName     LastName
-------------------------
1.  Tim           Tom
2.  Tim           Tim
3.  Peter         Tim Timar

```

The results for "search request" `"Ti* AND Ti*"` should be:

* **Nr. 2** (1 match in FirstName, 1 match in LastName)
* and **Nr. 3** (2 matches in LastName)
* but not Nr. 1 (since it has only 1 match at all).

**Btw:** Here I tried to simplify the domain I am working with. In the real scenario I have more than two fields to search for, that's why I need a generic solution

Answer: 
Lucene is an inverted index structure, so it mainly doesn't care on count of matches inside a single document.  

The document is retrieved because a *term* matches with the query. 

Writing \*\*tim\* AND tim\* \*\* or \*\*tim\* \*\*, has the same effect.
As Alessandro suggested, you can specify on which indexed field apply the query.
Note that this isn't a Orient issue nor a Lucene one: this is the way Lucene is supposed to work.
Try 

```
select from User where [FirstName,LastName] LUCENE "(FirstName:Peter AND LastName:Peter)"

```

You can see at this link <http://orientdb.com/docs/2.0/orientdb-lucene.wiki/Full-Text-Index.html#working-with-multiple-field>

Edited

Try to create a function js 
Example : my Function with parameter myClass and property

```
var g=orient.getGraph();
var b=g.command("sql","select from "+ myClass);
property=property.substring(1,property.length-1).split(",");
var array=[];
for(i=0;i<b.length;i++){
  var count=0;
  for(j=0;j<property.length;j++){
        var myString=b[i].getProperty(property[j]);
        count = count + (myString.match(/Tim+/g) || []).length;
  }
  if(count>=property.length){
    array.push(b[i]);
  }
}
return array;

```

and use this command `select expand(result) from (select myFunction("User","[FirstName,LastName]") as result)`