AngularJS filter multiple words from a string in a single field
<p>Here the idea of my problem :</p>

<p>Imagine, I have an user looking for a book.</p>

<p>As input, he can try to find the book using book title.</p>

<p>Let's take :</p>

<pre><code>  $scope.books = ["Heir Of Earth",
    "Woman Of The Solstice",
    "Hunters Of Next Year",
    "Pilots Without Honor",
    "Slaves And A Woman",
    "Kings And Heroes",
    "Decay Of The End",
    "Fortune Of The Land",
    "Rejecting My Dreams",
    "Painting The Angels"];
</code></pre>

<p>Now I take the user query in a string :</p>

<p><strong>example :</strong></p>

<pre><code>$scope.userQueryTitle = "Woman Of";
</code></pre>

<p>I want to get all books which where their title contains "Woman" or "Of" but NOT "Woman" AND "Of".</p>

<p>From there, the corresponding result should be this :</p>

<pre><code>$scope.booksResult = ["Heir Of Earth",
"Woman Of The Solstice",
"Hunters Of Next Year",
"Slaves And A Woman",
"Decay Of The End",
"Fortune Of The Land"
];
</code></pre>

<p>I found some partial solutions to my problem such as use something like :</p>

<p>View:</p>

<pre><code>&lt;ul ng-repeat="book in booksResult | filter: getBooksFromTitle"&gt;
    &lt;li&gt;{{book}}&lt;/li&gt;
&lt;/ul&gt;
</code></pre>

<p>Controller:</p>

<pre><code>$scope.getBooksFromTitle = function(book){
    return book.match(($scope.userQueryTitle).split(" ")[0]) || 
        book.match(($scope.userQueryTitle).split(" ")[1]);
};
</code></pre>

<p>It works only if <code>$scope.userQueryTitle</code> contains only 2 words but <strong>my problem is</strong> what's about if I have <strong>1</strong> or <strong>4</strong> or <strong>n</strong> word(s) ?</p>

<p><code>getBooksFromTitle()</code> should be flexible about this but I don't see how to deal with...</p>

<p>Any suggestion ?</p>

<p>Thanks !</p>