Tigran
Tigran

Reputation: 11

Searching in SOLR fields that dont exist

So I have Users who have some fields like [Field A] and [ Field B]. Fields can be empty or can not exists (user wont add there nothing).

Now my query is like that:

Field A:Green

Solr give me 100users who have green field.

I want to filter from this 100 users with some boosting

FieldA: Green AND (FieldB:Blue OR FieldB:*)

Not it will give me all fields with Blue or all fields which have something in this fields. But i want people who don't have this field too.

I try:

FieldA: Green AND (FieldB:Blue OR FieldB:* OR (-FieldB:*))

but it doesn't work

Upvotes: 0

Views: 109

Answers (2)

Tigran
Tigran

Reputation: 11

Ok maybe i will explain my problem again:

I have two fields: Name and Surname. I have 10 records with name:BOB and 3 records with surname: SMITH

First i filter:

name:BOB and query give me 10 records.

Now i want to filter all people who are Bob Smith and THEN i want to have people with name bob (Name BOB is obligatory) then i want people who have something else in fields Surname.

so my query looks like this:

name:BOB AND (surname:SMITH^3 or surname:^0) - This give me people which name must be bob and on first people with surname smith, then people with other values. But "surname:" dont give me people with empty field. So i try doing (-surname:*^0) but it didnt work.

Now people who have ONLY name BOB but dont have anything in surname are disabled from results

Upvotes: 1

rvegas
rvegas

Reputation: 78

Why don't you try saving a fixed value for empty field.

So you could have: FieldA: Blue FieldB: 0

Then simply query FieldA: Green AND (FieldB:Blue OR FieldB:0)

You could also switch your FieldB:* to FieldB:[* TO *]

Upvotes: 1

Related Questions