Constant boost multivalued fields in Solr - boost

I have a multivalued field storing strings which I need to perform queries on. It stores IDs as strings. So, this is the field:
<field name="id" type="string" indexed="true" stored="true" multiValued="true" termVectors="true"/>
And the the query would look like
q: (id:'23' OR id:'24')^2
This filters out documents where the field is 23 or 24. The documents which have both of those IDs are at the top, the documents which have either of those IDs are below.
What I want is a constant boost of 2. If at least one ID matches, give it a boost of 2. How do I achieve something like that?

One possible option is to convert this query to the ConstantScoreQuery, by replacing ^ with ^=
q: (id:'23' OR id:'24')^=2
In this case, if your document will have both terms 23 and 24 or just having either of them you will still have the same score of 2.0

Related

Sorting Truncated Date in Solr

I am currently using solr 7.1.0. I have indexed a few documents which have a date associated with it.
The Managed schema configuration for that field is :
<fieldType name="pdate" class="solr.DatePointField" docValues="true"/>
<field name="Published_Date" type="pdate" multiValued="false" indexed="true" stored="true"/>
Example of few values are :
"Published_Date":"2019-10-25T00:00:00Z",
"Published_Date":"2019-10-21T10:00:00Z"
Please help me in finding how I could achieve the following
I want to sort the documents based on these Published_Date parameters but only on the day(not the time/timezones)
Sorting on the basis of
"Published_Date":'2019-10-25'

Solr: different sort result between 2 core

I have this 2 core of solr, one called catalogs and the others special_page. It contains data from the same db, the difference is catalogs contain more field than the others (catalogs is in solr 5 and special in solr 4, yes differ solr version).
Problem is, when I have to sort this particular data, eg. special_page which id is 1 then sort by product_scroring desc. This 2 core having different order of results.
catalogs schema for product scoring : <field name="product_scoring" type="text_general" indexed="true" stored="true" multiValued="false" default=""/>
special_page schema for product_scoring : <field name="product_scoring" type="text_general" indexed="true" stored="true"/>
Can anyone suggest me what would make this 2 core produce same order of result? Thanks
If you're actually indexing float values, don't index them as text. Text will split the content into separate tokens based on multiple separators, such as "." and whitespace. Depending on how exact you need the values to be, using a double or float is a possibility (but remember, doubles and floats are not exact).
Secondly, since the value in the fields are identical, the ordering between documents are undefined (.. or it will default to the order they've been added in, but that may change and may not be the same across both cores). Use a secondary, stable field (such as the name, id, date added, etc.) to get identical sorting of the same data across cores (this is also why a cursorMark requires sorting by a unique key when used).
Problem is that: Solr will sort data with same value in random manner , If u will try again and again same query then the order of sorting will change for the same value. I think this is the problem

SolR - Search for room availability and sort by result

I'm trying to implement a kind of hotel/hostel search using SolR and PHP. For any room available I store a new document inside my index containing relevant information about the accomodation and multivalued attributes containing an availableFrom and availableTill date. Running a query against SolR to get all rooms within a certain timespan shouldn't be that hard, but my brain screws up when it comes to sorting...
My goal is to show not only the available accomodations, but all of them matching a general filter query on the destination (country/city/district) and sort these results so that all available rooms are sorted to the start of the list.
So for a search for rooms in Munich from 1st December '12 till 5th December, I would like to get results like these:
Room A (available)
Room B (available)
Room C (not completly available in the given period => nice to have)
Room D (not available at all)
Currently I'm running SolR 3.6 but could switch to the new 4.0 if necessary.
Has any Solr-Guru out there some suggestions for me?
Any help appreciated :-)
-edit-
I think Samuele pushed me in the right direction. So the question is now, how to create a function query to be able to sort by availability. Maybe there is a better way to store my document, i.e. change my schema.xml?
Here is a litte excerpt from it:
<field name="recordId" type="string" indexed="true" stored="true" />
<field name="language" type="int" indexed="true" stored="true" />
<field name="name" type="string" indexed="true" stored="false" />
<field name="maxPersons" type="int" indexed="true" stored="false" />
<field name="avgPrice" type="tdouble" indexed="true" stored="false" />
<field name="city" type="freetext" indexed="true" stored="false" />
<field name="district" type="freetext" indexed="true" stored="false" />
<field name="country" type="freetext" indexed="true" stored="false" />
<field name="availableFrom" type="date" indexed="true" stored="true" multiValued="true" />
<field name="availableTill" type="date" indexed="true" stored="true" multiValued="true" />
Cheers - Sven
well, you have to boost your query based on the field "rooms" (or availability, depends on you) and give different scores based on the value
quick example:
let's give an available room a boost of 20, a partial available a boost of 10 and not available a boost of 1 (just to be sure)
your query (url-wise, i don't know the php interface to solr) would need something like
<query>&bq=rooms:avail^20.0&bq=rooms:part-avail^10.0...
suggestions: if you're using dismax query handler, it's addictive. this means you'll have to add a bigger boost than that (2000 instead of 20 for example) since it adds the boosting value to the query score
also, you should check this link from the solr wiki, which is better than any explanation.
Well, I did some research and testing on the whole thing here... The currect and possibly best solution for my problem is to perform multiple queries against SolR. As suggested by Samuele I query SolR for all accomodations matching the given criteria and timespan in two steps.
1: Get all rooms matching and being available (this includes partially available rooms)
2: Get all unavailable rooms
The second query is obviously only performed when we need to show more results 'cos of the pagination.
After that all results from step 1 are postprocessed to figure out if they are available in the whole requested timespan.
A further "improvement" would be to introduce a new field in the schema: availableDay. For each bookable day there would be an entry for that date. This would split up the first query into two seperate ones. This is then only a matter of additional filters for SolR.
Thanks again for pointing me in the right direction!

several ordenation needs in the same request

i have a doubt about solr possibilities. i need to do a request with special issues:
i need first: promoted records with all the terms typed by the user (ordered randomly).
second: promoted records with any term typed by the user (ordered randomly).
third: promoted records found by the stemming search (ordered randomly).
fourth: promoted records found by the phonetic search (randomly).
fifth: free records ordered alphabeticly (having all or any term typed by the user).
these results need to be paginated.
is it possible to do it in the same request?
After finding out that random ordering is support in solr via:
<fieldType name="random" class="solr.RandomSortField" />
<field name="random" type="random" indexed="true" stored="false"/>
those queries will be possible but NOT in one query
Although one could use the facet and facet.query feature, but this only returns the count ... not the docs.
I would setup a separate advertising index instead of the normal way to implement 'advertising' with the elevation component
promoted records with all the terms typed by the user (ordered randomly)
a simple AND query against the advertising index
promoted records with any term typed by the user (ordered randomly)
a simple OR query against the advertising index
promoted records found by the stemming search (ordered randomly).
normal search (with stemming) in the advertisment index.
promoted records found by the phonetic search (randomly).
you'll need to transform the query and the terms via your own phonetic transformation to do that. so you'll have a special field phonetic_text and you'll need to query this via
q=phonetic_text:"U R G8" (which means: you are great ;-))
free records ordered alphabeticly (having all or any term typed by the user).
again normal search via "AND" or "OR" with the sort parameter

Solr Query on Unique Integer Field

I have a field defined in schema.xml as:
<field name="id" type="integer" indexed="true" stored="true" required="true" />
It is also the uniqueKey for the schema.
I cannot perform a query on this field with the query url:
/select?q=4525&qf=id&fl=id,name%2Cscore
This returns no results, however, if I search on a different field(such as a text field), with a different query, I get many results, which include the stored id. Solr is working great for text fields, but I cannot query for items based on the unique id.
What am I missing? Are there other steps that need to be performed for indexing?
Looks like you're using the qf parameter the wrong way... it's only meant to be used to boost fields in dismax queries.
Use id:4525 instead, as in:
/select?q=id:4525&fl=id,name,score

Resources