Skip to content

Commit

Permalink
Cannot query with where after moreLikeThis #409
Browse files Browse the repository at this point in the history
  • Loading branch information
ml054 committed Mar 22, 2024
1 parent af158ed commit b592432
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Documents/Session/AbstractDocumentQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ export abstract class AbstractDocumentQuery<T extends object, TSelf extends Abst
: QueryOperatorToken.OR;

if (lastWhere
&& lastWhere.options.searchOperator) {
&& lastWhere.options?.searchOperator) {
token = QueryOperatorToken.OR; // default to OR operator after search if AND was not specified explicitly
}

Expand Down
35 changes: 35 additions & 0 deletions test/Ported/MoreLikeThis/MoreLikeThisTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
} from "../../../src";
import { MoreLikeThisOptions } from "../../../src/Documents/Queries/MoreLikeThis/MoreLikeThisOptions";
import { MoreLikeThisStopWords } from "../../../src/Documents/Queries/MoreLikeThis/MoreLikeThisStopWords";
import { assertThat } from "../../Utils/AssertExtensions";

export class DataIndex extends AbstractJavaScriptIndexCreationTask<Data, Pick<Data, "body" | "whitespaceAnalyzerField">> {

Expand Down Expand Up @@ -258,6 +259,40 @@ describe("MoreLikeThisTests", function () {
await assertMoreLikeThisHasMatchesFor("DataIndex", store, id);
});

it("can use whereEquals after moreLikeThis", async () => {
const key = "data/1-A";

{
const session = store.openSession();

await new DataIndex().execute(store);

for (let i = 0; i < 3; i++) {
const data = new Data();
data.body = "Body" + i;
data.whitespaceAnalyzerField = "test test";
await session.store(data);
}

await session.saveChanges();
await testContext.waitForIndexing(store);
}

{
const session = store.openSession();
const query = session
.query<any>({ indexName: "DataIndex" })
.moreLikeThis(f => f.usingDocument(b => b.whereEquals("id()", key)))
.whereEquals("body", "Body2");

const list = await query.all();
assertThat(query.toString())
.isEqualTo("from index 'DataIndex' where moreLikeThis(id() = $p0) and body = $p1");

assert.ok(list.length > 0);
}
});

it("can get results using term vectors and storage", async () => {
let id: string;
{
Expand Down

0 comments on commit b592432

Please sign in to comment.